Archived

This forum has been archived. Please start a new discussion on GitHub.

My Ice Stats doesn't work??

ICE:3.0.1
VC++ 6.0

I use Ice in dll.

this is code in dll:

My Stats Class:

CStats_bytesSent stats_bytesSent;
CStats_bytesReceived Stats_bytesReceived;



class IceStats:virtual public Ice::Stats
{
public:


virtual void bytesSent(const string &prot,Ice::Int num)
{

if(stats_bytesSent=NULL) return;
stats_bytesSent(num);
};

virtual void bytesReceived(const string &prot,Ice::Int num)
{

if(Stats_bytesReceived=NULL) return;
Stats_bytesReceived(num);
};
};



typedef void (_stdcall *CPrintPos)(int result);

int _stdcall loadice(int argc, char *argv[])
{
if(printpos==NULL)
return ICE_CALLBACK_ERROR;

try
{

ic=Ice::initialize(argc,argv);

Ice::ObjectPrx base=ic->stringToProxy("print:default -p 10000");

print=printIPrx::checkedCast(base);

if(!print)
throw "Invalid proxy";

printcallback=new Cprintcallback();

return 0;

}
catch(const char *msg)
{

unloadice();
return -2;
}
};


int _stdcall sendmessage(int Messageid,void* Point)
{
switch(Messageid)
{
case ICE_FUNCTION_POINT:
{

printpos=CPrintPos(Point);

break;
}
case ICE_Request_Print:
{

print->print_async(printcallback);

break;
}
case ICE_STATS_ENABLE:
{
if(!ic) return ICE_STATS_ERROR;
if(!stats)
stats=new IceStats();

ic->setStats(stats);

}
case ICE_STATS_SEND:
{
if((Point=NULL)||(!ic)||(!stats)) return ICE_STATS_ERROR;
stats_bytesSent=CStats_bytesSent(Point);
}
case ICE_STATS_RECEIVED:
{
if((Point=NULL)||(!ic)||(!stats)) return ICE_STATS_ERROR;
Stats_bytesReceived=CStats_bytesReceived(Point);
}
}
return 0;
};

external Application:
step :
1.sendmessage(ICE_FUNCTION_POINT,callback);
2.loadice(0,nil);
3.sendmessage(ICE_STATS_ENABLE,nil);
4.sendmessage(ICE_STATS_SEND,Stats_bytesSent));
5.sendmessage(ICE_STATS_RECEIVED,Stats_bytesReceived));
6.sendmessage(ICE_Request_Print,nil);
·············
7.unloadice();


But My Ice Stats doesn't Work.

Comments

  • marc
    marc Florida
    You must set your stats object on the communicator right after communicator initialization. I recommend to use Ice 3.1, which has different initialization methods that avoid this mistake.
  • I have down ICE 3.1.But when use ic->setStat,the information tell me this function is not exist.How to use Ice::Stats??
  • marc
    marc Florida
    Communicator::setStats() does not exist anymore in Ice 3.1. You must set it during initialization. Please see "30.3 Communicator Initialization" in the Ice manual.
  • Thank you for your answer.
    But now the Problem still exists.

    I Change my code:

    struct Ice::InitializationData initdata;

    sendmessage function changed:

    case ICE_STATS_ENABLE:
    {

    if(!initdata.stats)

    initdata.stats=new IceStats();
    break;


    }
    case ICE_STATS_SEND:
    {
    if(Point=NULL) return ICE_STATS_ERROR;
    stats_bytesSent=CStats_bytesSent(Point);
    break;
    }
    case ICE_STATS_RECEIVED:
    {
    if(Point=NULL) return ICE_STATS_ERROR;
    Stats_bytesReceived=CStats_bytesReceived(Point);
    break;
    }
    }



    loadice function changed:

    ic=Ice::initialize(initdata);

    But when i call loadice function,the exception is called.
  • marc
    marc Florida
    I'm afraid I don't understand what you mean. What exception is raised? What exactly isn't working?
  • marc
    marc Florida
    Also, you cannot set the stats object in your sendmessage() operation. As explained before, you must set it for initialization. You cannot change the stats object after initialization, i.e., the reference to the stats object is immutable. If you need to switch on and off stats, then you must do this directly in your implementation of the Ice::Stats interface.