JNICCC.cpp
00001
00039 #include "JNICCC.h"
00040 #include "JNICCCFactory.h"
00041 #include "JNIHelpers.h"
00042
00043 JNIEnv* AttachToJVM(JavaVM* vm)
00044 {
00045 JNIEnv* env = NULL;
00046
00047 jint result = vm->GetEnv(reinterpret_cast<void**>(&env),JNI_VERSION_1_4);
00048
00049 if(result == JNI_EDETACHED)
00050 vm->AttachCurrentThread(reinterpret_cast<void**>(&env),NULL);
00051
00052 return env;
00053 }
00054
00055 JNICCC::JNICCC(JNIEnv* env, jobject objCCC) :
00056 _objCCC( env->NewGlobalRef(objCCC)){
00057
00058 env->GetJavaVM(&_javaVM);
00059
00060 if(_objCCC != NULL){
00061 jclass cccClass = env->GetObjectClass(_objCCC);
00062
00063
00064
00065 _methodInit = env->GetMethodID(cccClass, "init", "()V" );
00066 _methodClose = env->GetMethodID(cccClass, "close", "()V" );
00067 _methodOnACK = env->GetMethodID(cccClass, "onACK", "(I)V" );
00068 _methodOnLoss = env->GetMethodID(cccClass, "onLoss", "([I)V" );
00069 _methodTimeout = env->GetMethodID(cccClass, "onTimeout", "()V" );
00070 _methodOnPktSent = NULL;
00071 _methodProcessCustomMsg = NULL;
00072
00073 env->SetLongField(objCCC,udt_clsCCC_fld_nativeHandleID,(jlong)(intptr_t)this);
00074 }
00075 }
00076
00077 JNICCC::~JNICCC() {
00078
00079 JNIEnv* env = AttachToJVM(_javaVM);
00080
00081 if(_objCCC)
00082 env->DeleteGlobalRef(_objCCC);
00083 }
00084
00085 jobject JNICCC::getJavaCCC(){
00086 return _objCCC;
00087 }
00088
00089 void JNICCC::init(){
00090
00091 CCC::init();
00092
00093 if(_objCCC){
00094 JNIEnv* env = AttachToJVM(_javaVM);
00095 env->CallVoidMethod(_objCCC, _methodInit);
00096 }
00097 }
00098
00099 void JNICCC::close(){
00100
00101 CCC::close();
00102
00103 if(_objCCC){
00104 JNIEnv* env = AttachToJVM(_javaVM);
00105 env->CallVoidMethod(_objCCC, _methodClose);
00106 }
00107 }
00108
00109 void JNICCC::onACK(const int32_t& ack){
00110
00111 CCC::onACK(ack);
00112
00113 if(_objCCC){
00114 JNIEnv* env = AttachToJVM(_javaVM);
00115 env->CallVoidMethod(_objCCC, _methodOnACK, ack);
00116 }
00117 }
00118
00119 void JNICCC::onLoss(const int32_t* losslist, const int& size){
00120
00121 CCC::onLoss(losslist,size);
00122 }
00123
00124 void JNICCC::onTimeout(){
00125
00126 CCC::onTimeout();
00127
00128 if(_objCCC){
00129 JNIEnv* env = AttachToJVM(_javaVM);
00130 env->CallVoidMethod(_objCCC, _methodTimeout);
00131 }
00132 }
00133
00134 void JNICCC::onPktSent(const CPacket* pkt){
00135 CCC::onPktSent(pkt);
00136 }
00137
00138 void JNICCC::onPktReceived(const CPacket* pkt){
00139 CCC::onPktReceived(pkt);
00140 }
00141
00142 void JNICCC::processCustomMsg(const CPacket* pkt){
00143 CCC::processCustomMsg(pkt);
00144 }
00145
00146 void JNICCC::setACKTimer(const int& msINT){
00147 CCC::setACKTimer(msINT);
00148 }
00149
00150 void JNICCC::setACKInterval(const int& pktINT){
00151 CCC::setACKInterval(pktINT);
00152 }
00153
00154 void JNICCC::setRTO(const int& usRTO){
00155 CCC::setRTO(usRTO);
00156 }
00157
00158 void JNICCC::setPacketSndPeriod(const double sndPeriod){
00159 m_dPktSndPeriod = sndPeriod;
00160 }
00161
00162 void JNICCC::setCWndSize(const double cWndSize){
00163 m_dCWndSize = cWndSize;
00164 }
00165
00166 const CPerfMon* JNICCC::getPerfInfo(){
00167 return CCC::getPerfInfo();
00168 }
00169
00170
00171