Пример #1
0
/**************************************************************************
 * FUNCTION:      JNU_copyFromStringToSaNameT_NotNull
 * TYPE:          internal function
 * OVERVIEW:      copies the content of the specified String object to
 *                the specified SaNameT parameter.
 * INTERFACE:
 *   parameters:
 * 		fromStr [in]
 * 			- the source Java string. It must not be null.
 *          If longer than SA_MAX_NAME_LENGTH, AisInvalidParamException is thrown.
 *      toSaNamePtr [in/out]
 * 			- a pointer to the SaNameT structure into which
 * 			the content of the source Java string is copied.
 *
 *   returns:		JNI_TRUE if the copy operation succeeded.
 * 					If JNI_FALSE, then there is a pending Java exception.
 * NOTE:
 *************************************************************************/
jboolean JNU_copyFromStringToSaNameT_NotNull(JNIEnv *jniEnv,
					     jstring fromStr,
					     SaNameT *toSaNamePtr)
{
	// VARIABLES
	jsize _strLen;

	// BODY
	assert(fromStr != NULL);
	assert(toSaNamePtr != NULL);
	_TRACE2("NATIVE: Executing JNU_copyFromStringToSaNameT_NotNull(...)\n");
	// check if string is not too long
	_strLen = (*jniEnv)->GetStringUTFLength(jniEnv, fromStr);
	if (_strLen > SA_MAX_NAME_LENGTH) {
		_TRACE2("NATIVE ERROR: fromStr is too long %d\n", _strLen);
		JNU_throwNewByName(jniEnv,
				   "ais/AisInvalidParamException",
				   AIS_ERR_INVALID_PARAM_MSG);
		return JNI_FALSE;
	}
	// copy string content
	toSaNamePtr->length = (SaUint16T)_strLen;
	(*jniEnv)->GetStringUTFRegion(jniEnv,
				      fromStr,
				      (jsize)0,
				      (*jniEnv)->GetStringLength(jniEnv,
								 fromStr),
				      (char *)toSaNamePtr->value);
	assert((*jniEnv)->ExceptionCheck(jniEnv) == JNI_FALSE);
	_TRACE2
		("NATIVE: JNU_copyFromStringToSaNameT(...) returning normally\n");
	return JNI_TRUE;
}
/**************************************************************************
 * FUNCTION:  Java_org_opensaf_ais_amf_CsiManagerImpl_completedCsiQuiescing
 * TYPE:      native method
 *  Class:     ais_amf_CsiManager
 *  Method:    completedCsiQuiescing
 *  Signature: (JLorg/saforum/ais/AisStatus;)V
 *************************************************************************/
JNIEXPORT void JNICALL
Java_org_opensaf_ais_amf_CsiManagerImpl_completedCsiQuiescing(JNIEnv *jniEnv,
							      jobject
							      thisCsiManager,
							      jlong invocation,
							      jint error)
{
	// VARIABLES
	SaAmfHandleT _saAmfHandle;
	SaAisErrorT _saStatus;
	SaAisErrorT _error;
	// JNI
	jobject _amfLibraryHandle;

	// BODY

	assert(thisCsiManager != NULL);
	_TRACE2
		("NATIVE: Executing Java_org_opensaf_ais_amf_CsiManagerImpl_completedCsiQuiescing()\n");

	// get Java library handle
	_amfLibraryHandle = (*jniEnv)->GetObjectField(jniEnv,
						      thisCsiManager,
						      FID_amfLibraryHandle);

	assert(_amfLibraryHandle != NULL);

	// get native library handle
	_saAmfHandle = (SaAmfHandleT)(*jniEnv)->GetLongField(jniEnv,
							     _amfLibraryHandle,
							     FID_saAmfHandle);

	// convert AisStatus -> int
	// MODIFICATION: screwed up
	_error = (SaAisErrorT)error;

	// call saAmfCSIQuiescingComplete
	_saStatus = saAmfCSIQuiescingComplete(_saAmfHandle,
					      (SaInvocationT)invocation,
					      (SaAisErrorT)_error);

	_TRACE2
		("NATIVE: saAmfCSIQuiescingComplete(...) has returned with %d...\n",
		 _saStatus);

	// error handling
	if (_saStatus != SA_AIS_OK) {
		switch (_saStatus) {
		case SA_AIS_ERR_LIBRARY:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisLibraryException",
					   AIS_ERR_LIBRARY_MSG);
			break;
		case SA_AIS_ERR_TIMEOUT:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisTimeoutException",
					   AIS_ERR_TIMEOUT_MSG);
			break;
		case SA_AIS_ERR_TRY_AGAIN:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisTryAgainException",
					   AIS_ERR_TRY_AGAIN_MSG);
			break;
		case SA_AIS_ERR_BAD_HANDLE:
			// TODO library handle invalid (e.g finalized): this check could be done at Java level!
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisBadHandleException",
					   AIS_ERR_BAD_HANDLE_MSG);
			break;
		case SA_AIS_ERR_INVALID_PARAM:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisInvalidParamException",
					   AIS_ERR_INVALID_PARAM_MSG);
			break;
		case SA_AIS_ERR_NO_MEMORY:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisNoMemoryException",
					   AIS_ERR_NO_MEMORY_MSG);
			break;
		case SA_AIS_ERR_NO_RESOURCES:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisNoResourcesException",
					   AIS_ERR_NO_RESOURCES_MSG);
			break;
		default:
			// this should not happen here!

			assert(JNI_FALSE);

			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisLibraryException",
					   AIS_ERR_LIBRARY_MSG);
			break;
		}
		return;		// EXIT POINT!!!
	}
	// normal exit

	_TRACE2
		("NATIVE: Java_org_opensaf_ais_amf_CsiManagerImpl_completedCsiQuiescing() returning normally\n");

}
/**************************************************************************
 * FUNCTION:  Java_org_opensaf_ais_amf_CsiManagerImpl_getHaState
 * TYPE:      native method
 *  Class:     ais_amf_CsiManager
 *  Method:    getHaState
 *  Signature: (Ljava/lang/String;Ljava/lang/String;)Lorg/saforum/ais/amf/HaState;
 *************************************************************************/
JNIEXPORT jobject JNICALL
Java_org_opensaf_ais_amf_CsiManagerImpl_getHaState(JNIEnv *jniEnv,
						   jobject thisCsiManager,
						   jstring componentName,
						   jstring csiName)
{
	// VARIABLES
	SaNameT _saComponentName;
	SaNameT *_saComponentNamePtr = &_saComponentName;
	SaNameT _saCsiName;
	SaNameT *_saCsiNamePtr = &_saCsiName;
	SaAmfHandleT _saAmfHandle;
	SaAmfHAStateT _saHaState = SA_AMF_HA_QUIESCING + 1;	// this is an invalid value...
	SaAisErrorT _saStatus;
	// JNI
	jobject _amfLibraryHandle;
	jobject _haState;

	// BODY

	assert(thisCsiManager != NULL);
	_TRACE2
		("NATIVE: Executing Java_org_opensaf_ais_amf_CsiManagerImpl_getHaState()\n");

	// get Java library handle
	_amfLibraryHandle = (*jniEnv)->GetObjectField(jniEnv,
						      thisCsiManager,
						      FID_amfLibraryHandle);

	assert(_amfLibraryHandle != NULL);

	// get native library handle
	_saAmfHandle = (SaAmfHandleT)(*jniEnv)->GetLongField(jniEnv,
							     _amfLibraryHandle,
							     FID_saAmfHandle);
	// copy Java component name object
	if (JNU_copyFromStringToSaNameT(jniEnv,
					componentName,
					&_saComponentNamePtr) != JNI_TRUE) {
		return NULL;	// EXIT POINT! Exception pending...
	}

	U_printSaName("NATIVE: component name is ", _saComponentNamePtr);

	// copy Java CSI name object
	if (JNU_copyFromStringToSaNameT(jniEnv,
					csiName, &_saCsiNamePtr) != JNI_TRUE) {
		return NULL;	// EXIT POINT! Exception pending...
	}

	U_printSaName("NATIVE: CSI name is ", _saCsiNamePtr);
	_TRACE2
		("NATIVE: _saHaState before calling saAmfHAStateGet(...) is: %d\n",
		 _saHaState);

	// call saAmfHAStateGet
	_saStatus = saAmfHAStateGet(_saAmfHandle,
				    _saComponentNamePtr,
				    _saCsiNamePtr, &_saHaState);

	_TRACE2
		("NATIVE: _saHaState after saAmfHAStateGet(...) has returned is: %d\n",
		 _saHaState);
	_TRACE2("NATIVE: saAmfHAStateGet(...) has returned with %d...\n",
		_saStatus);

	// error handling
	if (_saStatus != SA_AIS_OK) {
		switch (_saStatus) {
		case SA_AIS_ERR_LIBRARY:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisLibraryException",
					   AIS_ERR_LIBRARY_MSG);
			break;
		case SA_AIS_ERR_TIMEOUT:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisTimeoutException",
					   AIS_ERR_TIMEOUT_MSG);
			break;
		case SA_AIS_ERR_TRY_AGAIN:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisTryAgainException",
					   AIS_ERR_TRY_AGAIN_MSG);
			break;
		case SA_AIS_ERR_BAD_HANDLE:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisBadHandleException",
					   AIS_ERR_BAD_HANDLE_MSG);
			break;
		case SA_AIS_ERR_INVALID_PARAM:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisInvalidParamException",
					   AIS_ERR_INVALID_PARAM_MSG);
			break;
		case SA_AIS_ERR_NO_MEMORY:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisNoMemoryException",
					   AIS_ERR_NO_MEMORY_MSG);
			break;
		case SA_AIS_ERR_NO_RESOURCES:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisNoResourcesException",
					   AIS_ERR_NO_RESOURCES_MSG);
			break;
		case SA_AIS_ERR_NOT_EXIST:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisNotExistException",
					   AIS_ERR_NOT_EXIST_MSG);
			break;
		default:
			// this should not happen here!

			assert(JNI_FALSE);

			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisLibraryException",
					   AIS_ERR_LIBRARY_MSG);
			break;
		}
		return NULL;	// EXIT POINT! Exception pending...
	}
	// return HA state
	_haState = JNU_HaState_getEnum(jniEnv, _saHaState);
	if (_haState == NULL) {
		// this should not happen here!

		_TRACE2("NATIVE ERROR: _haState is NULL\n");

		return NULL;	// AisLibraryException thrown already...
	}

	U_printSaAmfHAState
		("NATIVE: Java_org_opensaf_ais_amf_CsiManagerImpl_getHaState(...) returning normally with HA state: ",
		 _saHaState);

	return _haState;
}
/**************************************************************************
 * FUNCTION:  Java_org_opensaf_ais_amf_ComponentRegistryImpl_unregisterProxiedComponent
 * TYPE:      native method
 *  Class:     ais_amf_ComponentRegistry
 *  Method:    unregisterProxiedComponent
 *  Signature: (Ljava/lang/String;)V
 *************************************************************************/
JNIEXPORT void JNICALL Java_org_opensaf_ais_amf_ComponentRegistryImpl_unregisterProxiedComponent(
    JNIEnv* jniEnv,
    jobject thisComponentRegistry,
    jstring proxiedComponentName )
{
    SaNameT _saProxyComponentName;
    SaNameT _saProxiedComponentName;
    SaNameT* _saProxiedComponentNamePtr = &_saProxiedComponentName;
    SaAmfHandleT _saAmfHandle;
    SaAisErrorT _saStatus;
    // JNI
    jobject _amfLibraryHandle;
    jstring _thisComponentName;

    // BODY

    assert( thisComponentRegistry != NULL );
    _TRACE2( "NATIVE: Executing Java_org_opensaf_ais_amf_ComponentRegistryImpl_unregisterProxiedComponent(...)\n" );


    // get Java library handle
    _amfLibraryHandle = (*jniEnv)->GetObjectField( jniEnv,
                                                   thisComponentRegistry,
                                                   FID_amfLibraryHandle );

    assert( _amfLibraryHandle != NULL );

    // get native library handle
    _saAmfHandle = (SaAmfHandleT) (*jniEnv)->GetLongField( jniEnv,
                                                           _amfLibraryHandle,
                                                           FID_saAmfHandle );
    // get Java component name
    _thisComponentName = (*jniEnv)->GetObjectField( jniEnv,
                                                    thisComponentRegistry,
                                                    FID_componentName );
    // copy Java component name object
    if( JNU_copyFromStringToSaNameT_NotNull( jniEnv,
		                                     _thisComponentName,
        		                             &_saProxyComponentName ) != JNI_TRUE ){
        return; // EXIT POINT! Exception pending...
    }
    // copy Java proxied component name object
    if( JNU_copyFromStringToSaNameT( jniEnv,
                                     proxiedComponentName,
                                     &_saProxiedComponentNamePtr ) != JNI_TRUE ){
        return; // EXIT POINT! Exception pending...
    }


    // call saAmfComponentUnregister
    _saStatus = saAmfComponentUnregister( _saAmfHandle,
                                          _saProxiedComponentNamePtr,
                                          &_saProxyComponentName );

    _TRACE2( "NATIVE: saAmfComponentUnregister(...) has returned with %d...\n", _saStatus );

    // error handling
    if( _saStatus != SA_AIS_OK ){
        switch( _saStatus ){
            case SA_AIS_ERR_LIBRARY:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisLibraryException",
                                    AIS_ERR_LIBRARY_MSG );
                break;
            case SA_AIS_ERR_TIMEOUT:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisTimeoutException",
                                    AIS_ERR_TIMEOUT_MSG );
                break;
            case SA_AIS_ERR_TRY_AGAIN:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisTryAgainException",
                                    AIS_ERR_TRY_AGAIN_MSG );
                break;
            case SA_AIS_ERR_BAD_HANDLE:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisBadHandleException",
                                    AIS_ERR_BAD_HANDLE_MSG );
                break;
            case SA_AIS_ERR_INVALID_PARAM:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisInvalidParamException",
                                    AIS_ERR_INVALID_PARAM_MSG );
                break;
            case SA_AIS_ERR_NO_MEMORY:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisNoMemoryException",
                                    AIS_ERR_NO_MEMORY_MSG );
                break;
            case SA_AIS_ERR_NO_RESOURCES:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisNoResourcesException",
                                    AIS_ERR_NO_RESOURCES_MSG );
                break;
            case SA_AIS_ERR_NOT_EXIST:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisNotExistException",
                                    AIS_ERR_NOT_EXIST_MSG );
                break;
            case SA_AIS_ERR_BAD_OPERATION:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisBadOperationException",
                                    AIS_ERR_BAD_OPERATION_MSG );
                break;
            default:
                // this should not happen here!

                assert( JNI_FALSE );

                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisLibraryException",
                                    AIS_ERR_LIBRARY_MSG );
                break;
        }
        return; // EXIT POINT! Exception pending...
    }


    _TRACE2( "NATIVE: Java_org_opensaf_ais_amf_ComponentRegistryImpl_unregisterProxiedComponent(...) returning normally\n" );


}
/**************************************************************************
 * FUNCTION:  Java_org_opensaf_ais_amf_ComponentRegistryImpl_invokeSaAmfComponentNameGet
 * TYPE:      native method
 *  Class:     ais_amf_ComponentRegistry
 *  Method:    invokeSaAmfComponentNameGet
 *  Signature: ()Ljava/lang/String;
 *************************************************************************/
JNIEXPORT jstring JNICALL Java_org_opensaf_ais_amf_ComponentRegistryImpl_invokeSaAmfComponentNameGet(
    JNIEnv* jniEnv,
    jobject thisComponentRegistry )
{
    // VARIABLES
    SaNameT _saComponentName;
    SaAmfHandleT _saAmfHandle;
    SaAisErrorT _saStatus;
    // JNI
    jobject _amfLibraryHandle;
    jstring _thisComponentName;

    // BODY

    assert( thisComponentRegistry != NULL );
    _TRACE2( "NATIVE: Executing Java_org_opensaf_ais_amf_ComponentRegistryImpl_invokeSaAmfComponentNameGet(...)\n" );


    // get Java library handle
    _amfLibraryHandle = (*jniEnv)->GetObjectField( jniEnv,
                                                   thisComponentRegistry,
                                                   FID_amfLibraryHandle );

    assert( _amfLibraryHandle != NULL );

    // get native library handle
    _saAmfHandle = (SaAmfHandleT) (*jniEnv)->GetLongField( jniEnv,
                                                           _amfLibraryHandle,
                                                           FID_saAmfHandle );

    // call saAmfComponentNameGet
    _saStatus = saAmfComponentNameGet( _saAmfHandle,
                                       &_saComponentName );

    _TRACE2( "NATIVE: saAmfComponentNameGet(...) has returned with %d...\n", _saStatus );

    // error handling
    if( _saStatus != SA_AIS_OK ){
        switch( _saStatus ){
            case SA_AIS_ERR_LIBRARY:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisLibraryException",
                                    AIS_ERR_LIBRARY_MSG );
                break;
            case SA_AIS_ERR_TIMEOUT:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisTimeoutException",
                                    AIS_ERR_TIMEOUT_MSG );
                break;
            case SA_AIS_ERR_TRY_AGAIN:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisTryAgainException",
                                    AIS_ERR_TRY_AGAIN_MSG );
                break;
            case SA_AIS_ERR_BAD_HANDLE:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisBadHandleException",
                                    AIS_ERR_BAD_HANDLE_MSG );
                break;
            case SA_AIS_ERR_INVALID_PARAM:

                assert( JNI_FALSE );

                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisLibraryException",
                                    AIS_ERR_LIBRARY_MSG );
                break;
            case SA_AIS_ERR_NO_MEMORY:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisNoMemoryException",
                                    AIS_ERR_NO_MEMORY_MSG );
                break;
            case SA_AIS_ERR_NO_RESOURCES:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisNoResourcesException",
                                    AIS_ERR_NO_RESOURCES_MSG );
                break;
            case SA_AIS_ERR_NOT_EXIST:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisNotExistException",
                                    AIS_ERR_NOT_EXIST_MSG );
                break;
            default:
                // this should not happen here!

                assert( JNI_FALSE );

                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisLibraryException",
                                    AIS_ERR_LIBRARY_MSG );
                break;
        }
        return NULL; // EXIT POINT! Exception pending...
    }

    // return Component name
    _thisComponentName = JNU_newStringFromSaNameT( jniEnv,
                                                   &_saComponentName );
    if( _thisComponentName == NULL ){
        // this should not happen here!

        assert( JNI_FALSE );

        JNU_throwNewByName( jniEnv,
                            "org/saforum/ais/AisLibraryException",
                            AIS_ERR_LIBRARY_MSG );
        return NULL; // EXIT POINT! Exception pending...
    }

    U_printSaName(  "NATIVE: Java_org_opensaf_ais_amf_ComponentRegistryImpl_invokeSaAmfComponentNameGet(...) returning normally with Component name: ",
                    &_saComponentName );

    return _thisComponentName;
}