Archived
This forum has been archived. Please start a new discussion on GitHub.
One Question
in Help Center
I want to write an class, so that another person can use my class to connect automatically with the server and use server objects.
An example:
I wrote an declaration of my class in "myClass.h" and the definition of my class in "myClass.cpp".
In my class definition there exists an method called "void setDataString(string value)".
Now I want to give this two files to another person, who uses them as follows:
He includes the header file "myClass.h".
Then he uses "myClass.setDataString("example");" in his source code.
And the methode "void setDataString(string value)" connect automatically to the server and
execute the methode "setDataString(string value)" on the server side.
But I don't want to use "argc, char* []" as parameters.
Another example:
I wrote the file "streamClient.cpp":
#include <dataStreamTransferIC.h>
int
main(int argc, char* argv[])
{
dataStreamClient dsc;
dsc.setDataString(argc, argv,"Dies ist nur ein Beispieltext!");
return 0;
}
"dataStreamTransferIC.h":
#include <Ice/Ice.h>
#include <dataStreamTransfer.h>
using namespace std;
using namespace dataStreamTransfer;
class dataStreamClient {
public:
void setDataString(int argc, char* argv[],string value);
};
"dataStreamTransferIC.cpp":
#include <IceGrid/IceGrid.h>
#include <Ice/Ice.h>
#include <dataStreamTransferIC.h>
#include <string.h>
using namespace std;
using namespace dataStreamTransfer;
void
dataStreamClient::setDataString(int argc, char* argv[],string value) {
Ice::CommunicatorPtr ic;
try {
ic = Ice::initialize(argc, argv);
Ice::ObjectPrx base = ic->stringToProxy(
"SimpleLogFile@FileStoreAdapter");
FileStorePrx stream = FileStorePrx::checkedCast(base);
if (!stream)
throw "Invalid proxy";
//stream->printString("Dies ist nur ein Beispieltext!");
int count = 0;
while(true) {
while(count < 1000000000) {
count++;
}
stream->setDataString(value);
count = 0;
}
//string result = stream->getDataString();
//cout << result << endl;
} catch (const Ice::Exception& ex) {
cerr << ex << endl;
} catch (const char* msg) {
cerr << msg << endl;
}
if (ic)
ic->destroy();
}
But what I try, is the following:
I want, the programm "streamClient.cpp" looks like:
#include <dataStreamTransferIC.h>
int
main(int argc, char* argv[])
{
while(true) {
dataStreamClient.setDataString("example!");
}
return 0;
}
That means, that I try to erase the parameters "argc" and "argv" in "setDataString".
But then I have to change "dataStreamTransferIC.h" and "dataStreamTransferIC.cpp".
And I try not to use the virtual class Ice::Application, because there is a virtual method
"run" with parameters "argc" and "argv".
How can I do this if possible???
An example:
I wrote an declaration of my class in "myClass.h" and the definition of my class in "myClass.cpp".
In my class definition there exists an method called "void setDataString(string value)".
Now I want to give this two files to another person, who uses them as follows:
He includes the header file "myClass.h".
Then he uses "myClass.setDataString("example");" in his source code.
And the methode "void setDataString(string value)" connect automatically to the server and
execute the methode "setDataString(string value)" on the server side.
But I don't want to use "argc, char* []" as parameters.
Another example:
I wrote the file "streamClient.cpp":
#include <dataStreamTransferIC.h>
int
main(int argc, char* argv[])
{
dataStreamClient dsc;
dsc.setDataString(argc, argv,"Dies ist nur ein Beispieltext!");
return 0;
}
"dataStreamTransferIC.h":
#include <Ice/Ice.h>
#include <dataStreamTransfer.h>
using namespace std;
using namespace dataStreamTransfer;
class dataStreamClient {
public:
void setDataString(int argc, char* argv[],string value);
};
"dataStreamTransferIC.cpp":
#include <IceGrid/IceGrid.h>
#include <Ice/Ice.h>
#include <dataStreamTransferIC.h>
#include <string.h>
using namespace std;
using namespace dataStreamTransfer;
void
dataStreamClient::setDataString(int argc, char* argv[],string value) {
Ice::CommunicatorPtr ic;
try {
ic = Ice::initialize(argc, argv);
Ice::ObjectPrx base = ic->stringToProxy(
"SimpleLogFile@FileStoreAdapter");
FileStorePrx stream = FileStorePrx::checkedCast(base);
if (!stream)
throw "Invalid proxy";
//stream->printString("Dies ist nur ein Beispieltext!");
int count = 0;
while(true) {
while(count < 1000000000) {
count++;
}
stream->setDataString(value);
count = 0;
}
//string result = stream->getDataString();
//cout << result << endl;
} catch (const Ice::Exception& ex) {
cerr << ex << endl;
} catch (const char* msg) {
cerr << msg << endl;
}
if (ic)
ic->destroy();
}
But what I try, is the following:
I want, the programm "streamClient.cpp" looks like:
#include <dataStreamTransferIC.h>
int
main(int argc, char* argv[])
{
while(true) {
dataStreamClient.setDataString("example!");
}
return 0;
}
That means, that I try to erase the parameters "argc" and "argv" in "setDataString".
But then I have to change "dataStreamTransferIC.h" and "dataStreamTransferIC.cpp".
And I try not to use the virtual class Ice::Application, because there is a virtual method
"run" with parameters "argc" and "argv".
How can I do this if possible???
0
Comments
-
Same Question
I changed the file "dataStreamTransferIC.h":
#include <Ice/Ice.h>
#include <dataStreamTransfer.h>
using namespace std;
using namespace dataStreamTransfer;
class dataStreamClient {
public:
Ice::CommunicatorPtr _ic;
FileStorePrx _stream;
public:
dataStreamClient(int, char**);
~dataStreamClient();
void setDataString(string value);
};
I changed the "dataStreamTransferIC.cpp" file:
#include <IceGrid/IceGrid.h>
#include <Ice/Ice.h>
#include <dataStreamTransferIC.h>
#include <string.h>
using namespace std;
using namespace dataStreamTransfer;
dataStreamClient::~dataStreamClient() {
if(dataStreamClient::_ic) {
try {
dataStreamClient::_ic->destroy();
}
catch (Ice::Exception& e) {
cerr << e << endl;
}
}
};
dataStreamClient::dataStreamClient(int argc,char* argv[]) {
try {
dataStreamClient::_ic = Ice::initialize(argc, argv);
Ice::ObjectPrx base = dataStreamClient::_ic->stringToProxy(
"SimpleLogFile@FileStoreAdapter");
dataStreamClient::_stream = FileStorePrx::checkedCast(base);
if (!dataStreamClient::_stream)
throw "Invalid proxy";
} catch (const Ice::Exception& ex) {
cerr << ex << endl;
} catch (const char* msg) {
cerr << msg << endl;
}
};
void
dataStreamClient::setDataString(string value) {
dataStreamClient::_stream->setDataString(value);
};
I changed the "streamClient.cpp" file:
#include <dataStreamTransferIC.h>
int
main(int argc, char* argv[])
{
dataStreamClient stream(argc,argv);
stream.setDataString("Dies ist nur ein Beispieltext!");
return 0;
}
But I the apprehension, that the CommunicatorPtr _ic is not destroyed?
What is wrong?0 -
You can pass an empty argc and argv to Ice::Initialize if you don't want to use the command line arguments for your application.
If you want to use Ice::Application, unfortunately due to a bug with with Ice 3.3.0 this does not work (http://www.zeroc.com/forums/bug-reports/4289-ice-application-use-argv-0-without-checking-argc-0-a.html#post18954), so if you want to use an empty command line arguments, then you could either use the StringSeq main method, or ensure argc ==1 and argv[0] contains some valid string.
With respect to your second question, looking this code the communicator should be destroyed. Why do you think it isn't?
As a general note, posting large amounts of code inline in a post is not good. Either post smaller and more focused snippets, or alternatively attach a fully working and compilable example that demonstrates your issue if possible.0