예제 #1
0
파일: AllTests.cpp 프로젝트: joshmoore/ice
 void opExceptionPairNC(bool ok, const pair<const Ice::Byte*, const Ice::Byte*>& outParams)
 {
     if(ok)
     {
         test(false);
     }
     else
     {
         Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams);
         in->startEncapsulation();
         try
         {
             in->throwException();
         }
         catch(const Test::MyException&)
         {
             in->endEncapsulation();
             called();
         }
         catch(...)
         {
             test(false);
         }
     }
 }
예제 #2
0
파일: Exception.cpp 프로젝트: Jonavin/ice
void
Ice::UserException::__read(const Ice::InputStreamPtr& is)
{
    is->startException();
    __readImpl(is);
    is->endException(false);
}
예제 #3
0
파일: AllTests.cpp 프로젝트: joshmoore/ice
    void opString(const Ice::AsyncResultPtr& result)
    {
        string cmp = testString;
        if(_useCookie)
        {
            CookiePtr cookie = CookiePtr::dynamicCast(result->getCookie());
            cmp = cookie->getString();
        }

        Ice::ByteSeq outParams;
        if(result->getProxy()->end_ice_invoke(outParams, result))
        {
            Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams);
            in->startEncapsulation();
            string s;
            in->read(s);
            test(s == cmp);
            in->read(s);
            test(s == cmp);
            in->endEncapsulation();
            called();
        }
        else
        {
            test(false);
        };
    }
예제 #4
0
파일: AllTests.cpp 프로젝트: joshmoore/ice
 void opExceptionWC(bool ok, const Ice::ByteSeq& outParams, const CookiePtr& cookie)
 {
     test(cookie->getString() == testString);
     if(ok)
     {
         test(false);
     }
     else
     {
         Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams);
         in->startEncapsulation();
         try
         {
             in->throwException();
         }
         catch(const Test::MyException&)
         {
             in->endEncapsulation();
             called();
         }
         catch(...)
         {
             test(false);
         }
     }
 }
예제 #5
0
파일: AllTests.cpp 프로젝트: joshmoore/ice
    void opException(const Ice::AsyncResultPtr& result)
    {
        if(_useCookie)
        {
            CookiePtr cookie = CookiePtr::dynamicCast(result->getCookie());
            test(cookie->getString() == testString);
        }

        Ice::ByteSeq outParams;
        if(result->getProxy()->end_ice_invoke(outParams, result))
        {
            test(false);
        }
        else
        {
            Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams);
            in->startEncapsulation();
            try
            {
                in->throwException();
            }
            catch(const Test::MyException&)
            {
                in->endEncapsulation();
                called();
            }
            catch(...)
            {
                test(false);
            }
        }
    }
예제 #6
0
 void opStringWC(bool ok, const Ice::ByteSeq& outParams, const CookiePtr& cookie)
 {
     if(ok)
     {
         Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams);
         string s;
         in->read(s);
         test(s == cookie->getString());
         in->read(s);
         test(s == cookie->getString());
         called();
     }
     else
     {
         test(false);
     }
 }
예제 #7
0
 void opStringNC(bool ok, const Ice::ByteSeq& outParams)
 {
     if(ok)
     {
         Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams);
         string s;
         in->read(s);
         test(s == testString);
         in->read(s);
         test(s == testString);
         called();
     }
     else
     {
         test(false);
     }
 }
예제 #8
0
파일: AllTests.cpp 프로젝트: joshmoore/ice
 void opStringPairNC(bool ok, const pair<const Ice::Byte*, const Ice::Byte*>& outParams)
 {
     if(ok)
     {
         Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams);
         in->startEncapsulation();
         string s;
         in->read(s);
         test(s == testString);
         in->read(s);
         test(s == testString);
         in->endEncapsulation();
         called();
     }
     else
     {
         test(false);
     }
 }
예제 #9
0
 void opExceptionNC(bool ok, const Ice::ByteSeq& outParams)
 {
     if(ok)
     {
         test(false);
     }
     else
     {
         Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams);
         try
         {
             in->throwException();
         }
         catch(const Test::MyException&)
         {
             called();
         }
         catch(...)
         {
             test(false);
         }
     }
 }
예제 #10
0
파일: IceGridDB.cpp 프로젝트: joshmoore/ice
int
Client::run(int argc, char* argv[])
{
    IceUtilInternal::Options opts;
    opts.addOpt("h", "help");
    opts.addOpt("v", "version");
    opts.addOpt("d", "debug");
    opts.addOpt("", "import", IceUtilInternal::Options::NeedArg);
    opts.addOpt("", "export", IceUtilInternal::Options::NeedArg);
    opts.addOpt("", "dbhome", IceUtilInternal::Options::NeedArg);
    opts.addOpt("", "dbpath", IceUtilInternal::Options::NeedArg);
    opts.addOpt("", "mapsize", IceUtilInternal::Options::NeedArg);
    opts.addOpt("", "server-version", IceUtilInternal::Options::NeedArg);

    vector<string> args;
    try
    {
        args = opts.parse(argc, const_cast<const char**>(argv));
    }
    catch(const IceUtilInternal::BadOptException& e)
    {
        cerr << e.reason << endl;
        usage();
        return EXIT_FAILURE;
    }
    if(!args.empty())
    {
        cerr << argv[0] << ": too many arguments" << endl;
        usage();
        return EXIT_FAILURE;
    }

    if(opts.isSet("help"))
    {
        usage();
        return EXIT_SUCCESS;
    }

    if(opts.isSet("version"))
    {
        cout << ICE_STRING_VERSION << endl;
        return EXIT_SUCCESS;
    }

    if(!(opts.isSet("import") ^ opts.isSet("export")))
    {
        cerr << "Either --import or --export must be set" << endl;
        usage();
        return EXIT_FAILURE;
    }

    if(!(opts.isSet("dbhome") ^ opts.isSet("dbpath")))
    {
        cerr << "Set the database environment directory with either --dbhome or --dbpath" << endl;
        usage();
        return EXIT_FAILURE;
    }

    bool debug = opts.isSet("debug");
    bool import = opts.isSet("import");
    string dbFile = opts.optArg(import ? "import" : "export");
    string dbPath;
    if(opts.isSet("dbhome"))
    {
        dbPath = opts.optArg("dbhome");
    }
    else
    {
        dbPath = opts.optArg("dbpath");
    }

    string mapSizeStr = opts.optArg("mapsize");
    size_t mapSize = IceDB::getMapSize(atoi(mapSizeStr.c_str()));
    string serverVersion = opts.optArg("server-version");

    try
    {
        IceGrid::AllData data;

        IceDB::IceContext dbContext;
        dbContext.communicator = communicator();
        dbContext.encoding.major = 1;
        dbContext.encoding.minor = 1;

        if(import)
        {
            cout << "Importing database to directory `" << dbPath << "' from file `" << dbFile << "'" << endl;

            if(!IceUtilInternal::directoryExists(dbPath))
            {
                cerr << "Output directory does not exist: " << dbPath << endl;
                return EXIT_FAILURE;
            }

            StringSeq files = IcePatch2Internal::readDirectory(dbPath);
            if(!files.empty())
            {
                cerr << "Output directory is not empty: " << dbPath << endl;
                return EXIT_FAILURE;
            }

            ifstream fs(dbFile.c_str(), ios::binary);
            if(fs.fail())
            {
                cerr << "Could not open input file: " << strerror(errno) << endl;
                return EXIT_FAILURE;
            }
            fs.unsetf(ios::skipws);

            fs.seekg(0, ios::end);
            streampos fileSize = fs.tellg();
            fs.seekg(0, ios::beg);

            vector<Ice::Byte> buf;
            buf.reserve(static_cast<size_t>(fileSize));
            buf.insert(buf.begin(), istream_iterator<Ice::Byte>(fs), istream_iterator<Ice::Byte>());

            fs.close();

            if(!serverVersion.empty())
            {
                ValueFactoryPtr factory = new ValueFactoryI(serverVersion);
                communicator()->addValueFactory(factory, "::IceGrid::ServerDescriptor");
                communicator()->addValueFactory(factory, "::IceGrid::IceBoxDescriptor");
            }

            Ice::InputStreamPtr stream = Ice::wrapInputStream(communicator(), buf, dbContext.encoding);

            string type;
            int version;

            stream->read(type);
            if(type != "IceGrid")
            {
                cerr << "Incorrect input file type: " << type << endl;
                return EXIT_FAILURE;
            }
            stream->read(version);
            if(version / 100 == 305)
            {
                if(debug)
                {
                    cout << "Reading Ice 3.5.x data" << endl;
                }
                skipFilter = true;
            }
            stream->read(data);

            {
                IceDB::Env env(dbPath, 5, mapSize);
                IceDB::ReadWriteTxn txn(env);

                if(debug)
                {
                    cout << "Writing Applications Map:" << endl;
                }

                IceDB::Dbi<string, ApplicationInfo, IceDB::IceContext, Ice::OutputStreamPtr>
                apps(txn, "applications", dbContext, MDB_CREATE);

                for(ApplicationInfoSeq::const_iterator p = data.applications.begin(); p != data.applications.end(); ++p)
                {
                    if(debug)
                    {
                        cout << "  NAME = " << p->descriptor.name << endl;
                    }
                    apps.put(txn, p->descriptor.name, *p);
                }

                if(debug)
                {
                    cout << "Writing Adapters Map:" << endl;
                }

                IceDB::Dbi<string, AdapterInfo, IceDB::IceContext, Ice::OutputStreamPtr>
                adpts(txn, "adapters", dbContext, MDB_CREATE);

                for(AdapterInfoSeq::const_iterator p = data.adapters.begin(); p != data.adapters.end(); ++p)
                {
                    if(debug)
                    {
                        cout << "  NAME = " << p->id << endl;
                    }
                    adpts.put(txn, p->id, *p);
                }

                if(debug)
                {
                    cout << "Writing Objects Map:" << endl;
                }

                IceDB::Dbi<Identity, ObjectInfo, IceDB::IceContext, Ice::OutputStreamPtr>
                objs(txn, "objects", dbContext, MDB_CREATE);

                for(ObjectInfoSeq::const_iterator p = data.objects.begin(); p != data.objects.end(); ++p)
                {
                    if(debug)
                    {
                        cout << "  NAME = " << communicator()->identityToString(p->proxy->ice_getIdentity()) << endl;
                    }
                    objs.put(txn, p->proxy->ice_getIdentity(), *p);
                }

                if(debug)
                {
                    cout << "Writing Internal Objects Map:" << endl;
                }

                IceDB::Dbi<Identity, ObjectInfo, IceDB::IceContext, Ice::OutputStreamPtr>
                internalObjs(txn, "internal-objects", dbContext, MDB_CREATE);

                for(ObjectInfoSeq::const_iterator p = data.internalObjects.begin(); p != data.internalObjects.end(); ++p)
                {
                    if(debug)
                    {
                        cout << "  NAME = " << communicator()->identityToString(p->proxy->ice_getIdentity()) << endl;
                    }
                    internalObjs.put(txn, p->proxy->ice_getIdentity(), *p);
                }

                if(debug)
                {
                    cout << "Writing Serials Map:" << endl;
                }

                IceDB::Dbi<string, Long, IceDB::IceContext, Ice::OutputStreamPtr>
                srls(txn, "serials", dbContext, MDB_CREATE);

                for(StringLongDict::const_iterator p = data.serials.begin(); p != data.serials.end(); ++p)
                {
                    if(debug)
                    {
                        cout << "  NAME = " << p->first << endl;
                    }
                    srls.put(txn, p->first, p->second);
                }

                txn.commit();
                env.close();
            }
        }
        else
        {
            cout << "Exporting database from directory `" << dbPath << "' to file `" << dbFile << "'" << endl;

            {
                IceDB::Env env(dbPath, 5);
                IceDB::ReadOnlyTxn txn(env);

                if(debug)
                {
                    cout << "Reading Application Map:" << endl;
                }

                IceDB::Dbi<string, IceGrid::ApplicationInfo, IceDB::IceContext, Ice::OutputStreamPtr>
                applications(txn, "applications", dbContext, 0);

                string name;
                ApplicationInfo application;
                IceDB::ReadOnlyCursor<string, IceGrid::ApplicationInfo, IceDB::IceContext, Ice::OutputStreamPtr>
                appCursor(applications, txn);
                while(appCursor.get(name, application, MDB_NEXT))
                {
                    if(debug)
                    {
                        cout << "  APPLICATION = " << name << endl;
                    }
                    data.applications.push_back(application);
                }
                appCursor.close();

                if(debug)
                {
                    cout << "Reading Adapter Map:" << endl;
                }

                IceDB::Dbi<string, IceGrid::AdapterInfo, IceDB::IceContext, Ice::OutputStreamPtr>
                adapters(txn, "adapters", dbContext, 0);

                AdapterInfo adapter;
                IceDB::ReadOnlyCursor<string, IceGrid::AdapterInfo, IceDB::IceContext, Ice::OutputStreamPtr>
                adapterCursor(adapters, txn);
                while(adapterCursor.get(name, adapter, MDB_NEXT))
                {
                    if(debug)
                    {
                        cout << "  ADAPTER = " << name << endl;
                    }
                    data.adapters.push_back(adapter);
                }
                adapterCursor.close();

                if(debug)
                {
                    cout << "Reading Object Map:" << endl;
                }

                IceDB::Dbi<Identity, IceGrid::ObjectInfo, IceDB::IceContext, Ice::OutputStreamPtr>
                objects(txn, "objects", dbContext, 0);

                Identity id;
                ObjectInfo object;
                IceDB::ReadOnlyCursor<Identity, IceGrid::ObjectInfo, IceDB::IceContext, Ice::OutputStreamPtr>
                objCursor(objects, txn);
                while(objCursor.get(id, object, MDB_NEXT))
                {
                    if(debug)
                    {
                        cout << "  IDENTITY = " << communicator()->identityToString(id) << endl;
                    }
                    data.objects.push_back(object);
                }
                objCursor.close();

                if(debug)
                {
                    cout << "Reading Internal Object Map:" << endl;
                }

                IceDB::Dbi<Identity, IceGrid::ObjectInfo, IceDB::IceContext, Ice::OutputStreamPtr>
                internalObjects(txn, "internal-objects", dbContext, 0);

                IceDB::ReadOnlyCursor<Identity, IceGrid::ObjectInfo, IceDB::IceContext, Ice::OutputStreamPtr>
                iobjCursor(internalObjects, txn);
                while(iobjCursor.get(id, object, MDB_NEXT))
                {
                    if(debug)
                    {
                        cout << "  IDENTITY = " << communicator()->identityToString(id) << endl;
                    }
                    data.internalObjects.push_back(object);
                }
                iobjCursor.close();

                if(debug)
                {
                    cout << "Reading Serials Map:" << endl;
                }

                IceDB::Dbi<string, Long, IceDB::IceContext, Ice::OutputStreamPtr>
                serials(txn, "serials", dbContext, 0);

                Long serial;
                IceDB::ReadOnlyCursor<string, Long, IceDB::IceContext, Ice::OutputStreamPtr>
                serialCursor(serials, txn);
                while(serialCursor.get(name, serial, MDB_NEXT))
                {
                    if(debug)
                    {
                        cout << "  NAME = " << name << endl;
                    }
                    data.serials.insert(std::make_pair(name, serial));
                }
                serialCursor.close();

                txn.rollback();
                env.close();
            }

            Ice::OutputStreamPtr stream = Ice::createOutputStream(communicator(), dbContext.encoding);
            stream->write("IceGrid");
            stream->write(ICE_INT_VERSION);
            stream->write(data);
            pair<const Ice::Byte*, const Ice::Byte*> buf = stream->finished();

            ofstream fs(dbFile.c_str(), ios::binary);
            if(fs.fail())
            {
                cerr << "Could not open output file: " << strerror(errno) << endl;
                return EXIT_FAILURE;
            }
            fs.write(reinterpret_cast<const char*>(buf.first), buf.second - buf.first);
            fs.close();
        }
    }
    catch(const IceUtil::Exception& ex)
    {
        cerr << (import ? "Import" : "Export") << " failed:\n" << ex << endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
예제 #11
0
파일: AllTests.cpp 프로젝트: joshmoore/ice
Test::MyClassPrxPtr
allTests(const Ice::CommunicatorPtr& communicator)
{
    string ref = "test:" + getTestEndpoint(communicator, 0);
    Ice::ObjectPrxPtr base = communicator->stringToProxy(ref);
    test(base);

    Test::MyClassPrxPtr cl = ICE_CHECKED_CAST(Test::MyClassPrx, base);
    test(cl);

    Test::MyClassPrxPtr oneway = cl->ice_oneway();
    Test::MyClassPrxPtr batchOneway = cl->ice_batchOneway();

    cout << "testing ice_invoke... " << flush;

    {
        Ice::ByteSeq inEncaps, outEncaps;
        if(!oneway->ice_invoke("opOneway", ICE_ENUM(OperationMode, Normal), inEncaps, outEncaps))
        {
            test(false);
        }

        test(batchOneway->ice_invoke("opOneway", ICE_ENUM(OperationMode, Normal), inEncaps, outEncaps));
        test(batchOneway->ice_invoke("opOneway", ICE_ENUM(OperationMode, Normal), inEncaps, outEncaps));
        test(batchOneway->ice_invoke("opOneway", ICE_ENUM(OperationMode, Normal), inEncaps, outEncaps));
        test(batchOneway->ice_invoke("opOneway", ICE_ENUM(OperationMode, Normal), inEncaps, outEncaps));
        batchOneway->ice_flushBatchRequests();

        Ice::OutputStreamPtr out = Ice::createOutputStream(communicator);
        out->startEncapsulation();
        out->write(testString);
        out->endEncapsulation();
        out->finished(inEncaps);

        // ice_invoke
        if(cl->ice_invoke("opString", ICE_ENUM(OperationMode, Normal), inEncaps, outEncaps))
        {
            Ice::InputStreamPtr in = Ice::createInputStream(communicator, outEncaps);
            in->startEncapsulation();
            string s;
            in->read(s);
            test(s == testString);
            in->read(s);
            test(s == testString);
            in->endEncapsulation();
        }
        else
        {
            test(false);
        }

        // ice_invoke with array mapping
        pair<const ::Ice::Byte*, const ::Ice::Byte*> inPair(&inEncaps[0], &inEncaps[0] + inEncaps.size());
        if(cl->ice_invoke("opString", ICE_ENUM(OperationMode, Normal), inPair, outEncaps))
        {
            Ice::InputStreamPtr in = Ice::createInputStream(communicator, outEncaps);
            in->startEncapsulation();
            string s;
            in->read(s);
            test(s == testString);
            in->read(s);
            test(s == testString);
            in->endEncapsulation();
        }
        else
        {
            test(false);
        }
    }

    {
        Ice::ByteSeq inEncaps, outEncaps;
        if(cl->ice_invoke("opException", ICE_ENUM(OperationMode, Normal), inEncaps, outEncaps))
        {
            test(false);
        }
        else
        {
            Ice::InputStreamPtr in = Ice::createInputStream(communicator, outEncaps);
            in->startEncapsulation();
            try
            {
                in->throwException();
            }
            catch(const Test::MyException&)
            {
            }
            catch(...)
            {
                test(false);
            }
            in->endEncapsulation();
        }
    }

    cout << "ok" << endl;

    cout << "testing asynchronous ice_invoke... " << flush;
#ifdef ICE_CPP11_MAPPING

    {
        promise<bool> completed;
        Ice::ByteSeq inEncaps, outEncaps;
        oneway->ice_invoke_async(
            "opOneway",
            OperationMode::Normal,
            inEncaps,
            nullptr,
            [&](exception_ptr ex)
        {
            completed.set_exception(ex);
        },
        [&](bool)
        {
            completed.set_value(true);
        });

        test(completed.get_future().get());
    }

    {
        promise<bool> completed;
        Ice::ByteSeq inEncaps, outEncaps;
        Ice::OutputStreamPtr out = Ice::createOutputStream(communicator);
        out->startEncapsulation();
        out->write(testString);
        out->endEncapsulation();
        out->finished(inEncaps);

        cl->ice_invoke_async("opString", OperationMode::Normal, inEncaps,
                             [&](bool ok, vector<Ice::Byte> outParams)
        {
            outEncaps = move(outParams);
            completed.set_value(ok);
        },
        [&](exception_ptr ex)
        {
            completed.set_exception(ex);
        });
        test(completed.get_future().get());

        Ice::InputStreamPtr in = Ice::createInputStream(communicator, outEncaps);
        in->startEncapsulation();
        string s;
        in->read(s);
        test(s == testString);
        in->read(s);
        test(s == testString);
        in->endEncapsulation();
    }

    {
        promise<bool> completed;
        promise<void> sent;
        Ice::ByteSeq inEncaps, outEncaps;
        Ice::OutputStreamPtr out = Ice::createOutputStream(communicator);
        out->startEncapsulation();
        out->write(testString);
        out->endEncapsulation();
        out->finished(inEncaps);

        pair<const ::Ice::Byte*, const ::Ice::Byte*> inPair(&inEncaps[0], &inEncaps[0] + inEncaps.size());

        cl->ice_invoke_async("opString", OperationMode::Normal, inPair,
                             [&](bool ok, pair<const Ice::Byte*, const Ice::Byte*> outParams)
        {
            vector<Ice::Byte>(outParams.first, outParams.second).swap(outEncaps);
            completed.set_value(ok);
        },
        [&](exception_ptr ex)
        {
            completed.set_exception(ex);
        },
        [&](bool)
        {
            sent.set_value();
        });
        sent.get_future().get(); // Ensure sent callback was called
        test(completed.get_future().get());

        Ice::InputStreamPtr in = Ice::createInputStream(communicator, outEncaps);
        in->startEncapsulation();
        string s;
        in->read(s);
        test(s == testString);
        in->read(s);
        test(s == testString);
        in->endEncapsulation();
    }

    {
        promise<bool> completed;
        promise<void> sent;
        Ice::ByteSeq inEncaps, outEncaps;

        cl->ice_invoke_async("opException", OperationMode::Normal, inEncaps,
                             [&](bool ok, vector<Ice::Byte> outParams)
        {
            outEncaps = move(outParams);
            completed.set_value(ok);
        },
        [&](exception_ptr ex)
        {
            completed.set_exception(ex);
        },
        [&](bool)
        {
            sent.set_value();
        });
        sent.get_future().get(); // Ensure sent callback was called
        test(!completed.get_future().get());

        Ice::InputStreamPtr in = Ice::createInputStream(communicator, outEncaps);
        in->startEncapsulation();
        try
        {
            in->throwException();
            test(false);
        }
        catch(const Test::MyException&)
        {
        }
        catch(...)
        {
            test(false);
        }
    }
#else
    void (::Callback::*nullEx)(const Ice::Exception&) = 0;
    void (::Callback::*nullExWC)(const Ice::Exception&, const CookiePtr&) = 0;

    {
        CookiePtr cookie = new Cookie();

        Ice::ByteSeq inEncaps, outEncaps;
        Ice::AsyncResultPtr result = oneway->begin_ice_invoke("opOneway", Ice::Normal, inEncaps);
        if(!oneway->end_ice_invoke(outEncaps, result))
        {
            test(false);
        }

        Ice::OutputStreamPtr out = Ice::createOutputStream(communicator);
        out->startEncapsulation();
        out->write(testString);
        out->endEncapsulation();
        out->finished(inEncaps);

        // begin_ice_invoke with no callback
        result = cl->begin_ice_invoke("opString", Ice::Normal, inEncaps);
        if(cl->end_ice_invoke(outEncaps, result))
        {
            Ice::InputStreamPtr in = Ice::createInputStream(communicator, outEncaps);
            in->startEncapsulation();
            string s;
            in->read(s);
            test(s == testString);
            in->read(s);
            test(s == testString);
            in->endEncapsulation();
        }
        else
        {
            test(false);
        };

        // begin_ice_invoke with no callback and array mapping
        pair<const ::Ice::Byte*, const ::Ice::Byte*> inPair(&inEncaps[0], &inEncaps[0] + inEncaps.size());
        result = cl->begin_ice_invoke("opString", Ice::Normal, inPair);
        if(cl->end_ice_invoke(outEncaps, result))
        {
            Ice::InputStreamPtr in = Ice::createInputStream(communicator, outEncaps);
            in->startEncapsulation();
            string s;
            in->read(s);
            test(s == testString);
            in->read(s);
            test(s == testString);
            in->endEncapsulation();
        }
        else
        {
            test(false);
        };

        // begin_ice_invoke with Callback
        ::CallbackPtr cb = new ::Callback(communicator, false);
        cl->begin_ice_invoke("opString", Ice::Normal, inEncaps, Ice::newCallback(cb, &Callback::opString));
        cb->check();

        // begin_ice_invoke with Callback and Cookie
        cb = new ::Callback(communicator, true);
        cl->begin_ice_invoke("opString", Ice::Normal, inEncaps, Ice::newCallback(cb, &Callback::opString), cookie);
        cb->check();

        // begin_ice_invoke with Callback_Object_ice_invoke
        cb = new ::Callback(communicator, false);
        Ice::Callback_Object_ice_invokePtr d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringNC, nullEx);
        cl->begin_ice_invoke("opString", Ice::Normal, inEncaps, d);
        cb->check();

        // begin_ice_invoke with Callback_Object_ice_invoke with Cookie
        cb = new ::Callback(communicator, false);
        d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringWC, nullExWC);
        cl->begin_ice_invoke("opString", Ice::Normal, inEncaps, d, cookie);
        cb->check();

        // begin_ice_invoke with Callback_Object_ice_invoke and array mapping
        cb = new ::Callback(communicator, false);
        d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringNC, nullEx);
        cl->begin_ice_invoke("opString", Ice::Normal, inPair, d);
        cb->check();

        // begin_ice_invoke with Callback_Object_ice_invoke and array mapping with Cookie
        cb = new ::Callback(communicator, false);
        d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringWC, nullExWC);
        cl->begin_ice_invoke("opString", Ice::Normal, inPair, d, cookie);
        cb->check();
    }

    {
        CookiePtr cookie = new Cookie();
        Ice::ByteSeq inEncaps, outEncaps;

        // begin_ice_invoke with no callback
        Ice::AsyncResultPtr result = cl->begin_ice_invoke("opException", Ice::Normal, inEncaps);
        if(cl->end_ice_invoke(outEncaps, result))
        {
            test(false);
        }
        else
        {
            Ice::InputStreamPtr in = Ice::createInputStream(communicator, outEncaps);
            in->startEncapsulation();
            try
            {
                in->throwException();
            }
            catch(const Test::MyException&)
            {
            }
            catch(...)
            {
                test(false);
            }
            in->endEncapsulation();
        }

        // begin_ice_invoke with Callback
        ::CallbackPtr cb = new ::Callback(communicator, false);
        cl->begin_ice_invoke("opException", Ice::Normal, inEncaps, Ice::newCallback(cb, &Callback::opException));
        cb->check();

        // begin_ice_invoke with Callback and Cookie
        cb = new ::Callback(communicator, true);
        cl->begin_ice_invoke("opException", Ice::Normal, inEncaps, Ice::newCallback(cb, &Callback::opException),
                             cookie);
        cb->check();

        // begin_ice_invoke with Callback_Object_ice_invoke
        cb = new ::Callback(communicator, false);
        Ice::Callback_Object_ice_invokePtr d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opExceptionNC, nullEx);
        cl->begin_ice_invoke("opException", Ice::Normal, inEncaps, d);
        cb->check();

        // begin_ice_invoke with Callback_Object_ice_invoke with Cookie
        cb = new ::Callback(communicator, false);
        d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opExceptionWC, nullExWC);
        cl->begin_ice_invoke("opException", Ice::Normal, inEncaps, d, cookie);
        cb->check();
    }
#endif
    cout << "ok" << endl;
    return cl;
}
예제 #12
0
int
InvokeClient::run(int argc, char*[])
{
    if(argc > 1)
    {
        cerr << appName() << ": too many arguments" << endl;
        return EXIT_FAILURE;
    }

    Ice::ObjectPrx obj = communicator()->propertyToProxy("Printer.Proxy");

    menu();

    char ch;
    do
    {
        try
        {
            cout << "==> ";
            cin >> ch;
            if(ch == '1')
            {
                //
                // Marshal the in parameter.
                //
                Ice::ByteSeq inParams, outParams;
                Ice::OutputStreamPtr out = Ice::createOutputStream(communicator());
                out->startEncapsulation();
                out->write("The streaming API works!");
                out->endEncapsulation();
                out->finished(inParams);

                //
                // Invoke operation.
                //
                if(!obj->ice_invoke("printString", Ice::Normal, inParams, outParams))
                {
                    cout << "Unknown user exception" << endl;
                }
            }
            else if(ch == '2')
            {
                //
                // Marshal the in parameter.
                //
                Ice::ByteSeq inParams, outParams;
                Ice::OutputStreamPtr out = Ice::createOutputStream(communicator());
                out->startEncapsulation();
                Demo::StringSeq arr;
                arr.push_back("The");
                arr.push_back("streaming");
                arr.push_back("API");
                arr.push_back("works!");
                out->write(arr);
                out->endEncapsulation();
                out->finished(inParams);

                //
                // Invoke operation.
                //
                if(!obj->ice_invoke("printStringSequence", Ice::Normal, inParams, outParams))
                {
                    cout << "Unknown user exception" << endl;
                }
            }
            else if(ch == '3')
            {
                //
                // Marshal the in parameter.
                //
                Ice::ByteSeq inParams, outParams;
                Ice::OutputStreamPtr out = Ice::createOutputStream(communicator());
                out->startEncapsulation();
                Demo::StringDict dict;
                dict["The"] = "streaming";
                dict["API"] = "works!";
                out->write(dict);
                out->endEncapsulation();
                out->finished(inParams);

                //
                // Invoke operation.
                //
                if(!obj->ice_invoke("printDictionary", Ice::Normal, inParams, outParams))
                {
                    cout << "Unknown user exception" << endl;
                }
            }
            else if(ch == '4')
            {
                //
                // Marshal the in parameter.
                //
                Ice::ByteSeq inParams, outParams;
                Ice::OutputStreamPtr out = Ice::createOutputStream(communicator());
                out->startEncapsulation();
                out->write(Demo::green);
                out->endEncapsulation();
                out->finished(inParams);

                //
                // Invoke operation.
                //
                if(!obj->ice_invoke("printEnum", Ice::Normal, inParams, outParams))
                {
                    cout << "Unknown user exception" << endl;
                }
            }
            else if(ch == '5')
            {
                //
                // Marshal the in parameter.
                //
                Ice::ByteSeq inParams, outParams;
                Ice::OutputStreamPtr out = Ice::createOutputStream(communicator());
                out->startEncapsulation();
                Demo::Structure s;
                s.name = "red";
                s.value = Demo::red;
                out->write(s);
                out->endEncapsulation();
                out->finished(inParams);

                //
                // Invoke operation.
                //
                if(!obj->ice_invoke("printStruct", Ice::Normal, inParams, outParams))
                {
                    cout << "Unknown user exception" << endl;
                }
            }
            else if(ch == '6')
            {
                //
                // Marshal the in parameter.
                //
                Ice::ByteSeq inParams, outParams;
                Ice::OutputStreamPtr out = Ice::createOutputStream(communicator());
                out->startEncapsulation();
                Demo::StructureSeq arr;
                arr.push_back(Demo::Structure());
                arr.back().name = "red";
                arr.back().value = Demo::red;
                arr.push_back(Demo::Structure());
                arr.back().name = "green";
                arr.back().value = Demo::green;
                arr.push_back(Demo::Structure());
                arr.back().name = "blue";
                arr.back().value = Demo::blue;
                out->write(arr);
                out->endEncapsulation();
                out->finished(inParams);

                //
                // Invoke operation.
                //
                if(!obj->ice_invoke("printStructSequence", Ice::Normal, inParams, outParams))
                {
                    cout << "Unknown user exception" << endl;
                }
            }
            else if(ch == '7')
            {
                //
                // Marshal the in parameter.
                //
                Ice::ByteSeq inParams, outParams;
                Ice::OutputStreamPtr out = Ice::createOutputStream(communicator());
                out->startEncapsulation();
                Demo::CPtr c = new Demo::C;
                c->s.name = "blue";
                c->s.value = Demo::blue;
                out->write(c);
                out->writePendingObjects();
                out->endEncapsulation();
                out->finished(inParams);

                //
                // Invoke operation.
                //
                if(!obj->ice_invoke("printClass", Ice::Normal, inParams, outParams))
                {
                    cout << "Unknown user exception" << endl;
                }
            }
            else if(ch == '8')
            {
                //
                // Invoke operation.
                //
                Ice::ByteSeq inParams, outParams;
                if(!obj->ice_invoke("getValues", Ice::Normal, inParams, outParams))
                {
                    cout << "Unknown user exception" << endl;
                    continue;
                }

                //
                // Unmarshal the results.
                //
                Ice::InputStreamPtr in = Ice::createInputStream(communicator(), outParams);
                in->startEncapsulation();
                Demo::CPtr c;
                in->read(c);
                string str;
                in->read(str);
                in->readPendingObjects();
                in->endEncapsulation();
                cout << "Got string `" << str << "' and class: s.name=" << c->s.name
                     << ", s.value=" << c->s.value << endl;
            }
            else if(ch == '9')
            {
                //
                // Invoke operation.
                //
                Ice::ByteSeq inParams, outParams;
                if(obj->ice_invoke("throwPrintFailure", Ice::Normal, inParams, outParams))
                {
                    cout << "Expected exception" << endl;
                    continue;
                }

                Ice::InputStreamPtr in = Ice::createInputStream(communicator(), outParams);
                in->startEncapsulation();
                try
                {
                    in->throwException();
                }
                catch(const Demo::PrintFailure&)
                {
                    // Expected.
                }
                catch(const Ice::UserException&)
                {
                    cout << "Unknown user exception" << endl;
                }
                in->endEncapsulation();
            }
            else if(ch == 's')
            {
                Ice::ByteSeq inParams, outParams;
                obj->ice_invoke("shutdown", Ice::Normal, inParams, outParams);
            }
            else if(ch == 'x')
            {
                // Nothing to do.
            }
            else if(ch == '?')
            {
                menu();
            }
            else
            {
                cout << "unknown command `" << ch << "'" << endl;
                menu();
            }
        }
        catch(const Ice::Exception& ex)
        {
            cerr << ex << endl;
        }
    }
    while(cin.good() && ch != 'x');

    return EXIT_SUCCESS;
}
예제 #13
0
Test::MyClassPrx
allTests(const Ice::CommunicatorPtr& communicator)
{
    string ref = "test:default -p 12010";
    Ice::ObjectPrx base = communicator->stringToProxy(ref);
    test(base);

    Test::MyClassPrx cl = Test::MyClassPrx::checkedCast(base);
    test(cl);

    Test::MyClassPrx oneway = cl->ice_oneway();

    void (Callback::*nullEx)(const Ice::Exception&) = 0;
    void (Callback::*nullExWC)(const Ice::Exception&, const CookiePtr&) = 0;
    
    cout << "testing ice_invoke... " << flush;

    {
        Ice::ByteSeq inParams, outParams;
        if(!oneway->ice_invoke("opOneway", Ice::Normal, inParams, outParams))
        {
            test(false);
        }

        Ice::OutputStreamPtr out = Ice::createOutputStream(communicator);
        out->write(testString);
        out->finished(inParams);

        // ice_invoke
        if(cl->ice_invoke("opString", Ice::Normal, inParams, outParams))
        {
            Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams);
            string s;
            in->read(s);
            test(s == testString);
            in->read(s);
            test(s == testString);
        }
        else
        {
            test(false);
        }

        // ice_invoke with array mapping
        pair<const ::Ice::Byte*, const ::Ice::Byte*> inPair(&inParams[0], &inParams[0] + inParams.size());
        if(cl->ice_invoke("opString", Ice::Normal, inPair, outParams))
        {
            Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams);
            string s;
            in->read(s);
            test(s == testString);
            in->read(s);
            test(s == testString);
        }
        else
        {
            test(false);
        }
    }

    {
        Ice::ByteSeq inParams, outParams;
        if(cl->ice_invoke("opException", Ice::Normal, inParams, outParams))
        {
            test(false);
        }
        else
        {
            Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams);
            try
            {
                in->throwException();
            }
            catch(const Test::MyException&)
            {
            }
            catch(...)
            {
                test(false);
            }
        }
    }

    cout << "ok" << endl;

    cout << "testing asynchronous ice_invoke... " << flush;

    {
        CookiePtr cookie = new Cookie();

        Ice::ByteSeq inParams, outParams;
        Ice::AsyncResultPtr result = oneway->begin_ice_invoke("opOneway", Ice::Normal, inParams);
        if(!oneway->end_ice_invoke(outParams, result))
        {
            test(false);
        }
        
        Ice::OutputStreamPtr out = Ice::createOutputStream(communicator);
        out->write(testString);
        out->finished(inParams);

        // begin_ice_invoke with no callback
        result = cl->begin_ice_invoke("opString", Ice::Normal, inParams);
        if(cl->end_ice_invoke(outParams, result))
        {
            Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams);
            string s;
            in->read(s);
            test(s == testString);
            in->read(s);
            test(s == testString);
        }
        else
        {
            test(false);
        };

        // begin_ice_invoke with no callback and array mapping
        pair<const ::Ice::Byte*, const ::Ice::Byte*> inPair(&inParams[0], &inParams[0] + inParams.size());
        result = cl->begin_ice_invoke("opString", Ice::Normal, inPair);
        if(cl->end_ice_invoke(outParams, result))
        {
            Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams);
            string s;
            in->read(s);
            test(s == testString);
            in->read(s);
            test(s == testString);
        }
        else
        {
            test(false);
        };

        // begin_ice_invoke with Callback
        CallbackPtr cb = new Callback(communicator, false);
        cl->begin_ice_invoke("opString", Ice::Normal, inParams, Ice::newCallback(cb, &Callback::opString));
        cb->check();

        // begin_ice_invoke with Callback and Cookie
        cb = new Callback(communicator, true);
        cl->begin_ice_invoke("opString", Ice::Normal, inParams, Ice::newCallback(cb, &Callback::opString), cookie);
        cb->check();

        // begin_ice_invoke with Callback_Object_ice_invoke 
        cb = new Callback(communicator, false);
        Ice::Callback_Object_ice_invokePtr d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringNC, nullEx);
        cl->begin_ice_invoke("opString", Ice::Normal, inParams, d);
        cb->check();

        // begin_ice_invoke with Callback_Object_ice_invoke with Cookie
        cb = new Callback(communicator, false);
        d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringWC, nullExWC);
        cl->begin_ice_invoke("opString", Ice::Normal, inParams, d, cookie);
        cb->check();

        // begin_ice_invoke with Callback_Object_ice_invoke and array mapping
        cb = new Callback(communicator, false);
        d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringNC, nullEx);
        cl->begin_ice_invoke("opString", Ice::Normal, inPair, d);
        cb->check();

        // begin_ice_invoke with Callback_Object_ice_invoke and array mapping with Cookie
        cb = new Callback(communicator, false);
        d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringWC, nullExWC);
        cl->begin_ice_invoke("opString", Ice::Normal, inPair, d, cookie);
        cb->check();
    }

    {
        CookiePtr cookie = new Cookie();
        Ice::ByteSeq inParams, outParams;

        // begin_ice_invoke with no callback
        Ice::AsyncResultPtr result = cl->begin_ice_invoke("opException", Ice::Normal, inParams);
        if(cl->end_ice_invoke(outParams, result))
        {
            test(false);
        }
        else
        {
            Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams);
            try
            {
                in->throwException();
            }
            catch(const Test::MyException&)
            {
            }
            catch(...)
            {
                test(false);
            }
        }

        // begin_ice_invoke with Callback
        CallbackPtr cb = new Callback(communicator, false);
        cl->begin_ice_invoke("opException", Ice::Normal, inParams, Ice::newCallback(cb, &Callback::opException));
        cb->check();

        // begin_ice_invoke with Callback and Cookie
        cb = new Callback(communicator, true);
        cl->begin_ice_invoke("opException", Ice::Normal, inParams, Ice::newCallback(cb, &Callback::opException),
                             cookie);
        cb->check();

        // begin_ice_invoke with Callback_Object_ice_invoke
        cb = new Callback(communicator, false);
        Ice::Callback_Object_ice_invokePtr d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opExceptionNC, nullEx);
        cl->begin_ice_invoke("opException", Ice::Normal, inParams, d);
        cb->check();

        // begin_ice_invoke with Callback_Object_ice_invoke with Cookie
        cb = new Callback(communicator, false);
        d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opExceptionWC, nullExWC);
        cl->begin_ice_invoke("opException", Ice::Normal, inParams, d, cookie);
        cb->check();
    }

    cout << "ok" << endl;

    return cl;
}