//- ****************************************************************************
//- 
//- Copyright 2009 Sandia Corporation. Under the terms of Contract 
//- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains 
//- certain rights in this software.
//-
//- BSD Open Source License.
//- All rights reserved.
//- 
//- Redistribution and use in source and binary forms, with or without 
//- modification, are permitted provided that the following conditions are met:
//-
//-    * Redistributions of source code must retain the above copyright notice, 
//-      this list of conditions and the following disclaimer.
//-    * Redistributions in binary form must reproduce the above copyright 
//-      notice, this list of conditions and the following disclaimer in the 
//-      documentation and/or other materials provided with the distribution.
//-    * Neither the name of Sandia National Laboratories nor the names of its 
//-      contributors may be used to endorse or promote products derived from  
//-      this software without specific prior written permission.
//-
//- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
//- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
//- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
//- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
//- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
//- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
//- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
//- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
//- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
//- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
//- POSSIBILITY OF SUCH DAMAGE.
//-


//- ****************************************************************************
//-
//- Program:       PGL Java Native Interface (JNI) Library
//- Module:        $RCSfile: pglJavaUtil.h,v $
//- Revision:      $Revision: 1.5 $
//- Last Modified: $Date: 2013/02/25 15:47:54 $
//- Last Check-in: $Author: sballar $
//-
//- ****************************************************************************
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    $RCSfile: pglJavaUtil.h,v $
  Language:  C++
  Date:      $Date: 2013/02/25 15:47:54 $
  Version:   $Revision: 1.5 $

  MODIFIED FOR SANDIA NATIONAL LABS KNOWLEDGE BASE CLIENT GRID INTERFACE
  (GNEM PROJECT)  4/00

Copyright (c) 1993-2000 Ken Martin, Will Schroeder, Bill Lorensen 
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

 * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
   of any contributors may be used to endorse or promote products derived
   from this software without specific prior written permission.

 * Modified source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=========================================================================*/

#ifndef __pglJavaUtil_h
#define __pglJavaUtil_h

#include <string>
#include <vector>
#include <jni.h>

using namespace std;

class pglJavaObject;

extern JNIEXPORT int pglJavaGetId(JNIEnv *env, jobject obj);

extern JNIEXPORT int pglJavaRegisterNewObject(JNIEnv *env, jobject obj, void *ptr);
extern JNIEXPORT void pglJavaRegisterCastFunction(JNIEnv *env, jobject obj, int id, void *tcFunc);               
          
extern JNIEXPORT void *pglJavaGetPointerFromObject(JNIEnv *env, jobject obj, 
                                                   const string& result_type);

extern JNIEXPORT void pglJavaDeleteObject(JNIEnv *env, jobject obj);

extern JNIEXPORT void pglJavaDeleteObjectFromHash(JNIEnv *env, int id);
extern JNIEXPORT jobject pglJavaGetObjectFromPointer(void *ptr);
extern JNIEXPORT int  pglJavaShouldIDeleteObject(JNIEnv *env, jobject obj);
extern JNIEXPORT char *pglJavaUTFToChar(JNIEnv *env, jstring in);
extern JNIEXPORT void  pglJavaUTFToString(JNIEnv *env, jstring in, string& s);
extern JNIEXPORT jstring pglJavaMakeJavaString(JNIEnv *env, const char *in);
extern JNIEXPORT jstring pglJavaMakeJavaString(JNIEnv *env, string in);

extern JNIEXPORT void javaMakeArrayOfDoubleFromJArray(JNIEnv *env,
		jdoubleArray javaArray, double doubleArray[], const int& maxSize, int& size);

extern JNIEXPORT void javaMakeVectorOfDoubleFromJArray(JNIEnv *env,
 jdoubleArray javaArray, vector<double>& doubleVector);

extern JNIEXPORT void javaMakeVectorOfIntFromJArray(JNIEnv *env, jintArray javaArray, vector<int>& intVector);

extern JNIEXPORT void javaMakeVectorOfBoolFromJArray(JNIEnv *env, jbooleanArray javaArray, vector<bool>& boolVector);

extern JNIEXPORT jarray javaMakeVectorOfIntFromJArray(JNIEnv *env, const vector<double>& doubleVector);

extern JNIEXPORT jarray javaMakeJArrayOfFloatFromVector(JNIEnv *env, const vector<float>& floatVector);

extern JNIEXPORT jarray javaMakeJArrayOfDoubleFromVector(JNIEnv *env, const vector<double>& doubleVector);

extern JNIEXPORT jarray javaMakeJArrayOfIntFromVector(JNIEnv *env, const vector<int>& intVector);

extern JNIEXPORT jarray javaMakeJArrayOfBoolFromVector(JNIEnv *env, const vector<bool>& boolVector);

extern JNIEXPORT jobjectArray javaMakeJArrayOfStringFromVector(JNIEnv *env, const vector<string>& stringVector);

extern JNIEXPORT jarray pglJavaMakeJArrayOfDoubleFromFloat(JNIEnv *env,
                                                           float *arr,
                                                           int size);
extern JNIEXPORT jarray pglJavaMakeJArrayOfDoubleFromDouble(JNIEnv *env, 
                                                            double *arr,
                                                            int size);
extern JNIEXPORT jarray pglJavaMakeJArrayOfDoubleFromDouble(JNIEnv *env, 
                                                             const double *arr, int size);
extern JNIEXPORT jarray pglJavaMakeJArrayOfIntFromInt(JNIEnv *env, int *arr, int size);

extern JNIEXPORT jobject pglJavaCreateNewJavaStubForObject(JNIEnv *env, pglJavaObject* obj);
extern JNIEXPORT jobject pglJavaCreateNewJavaStub(JNIEnv *env,
                                                  const char* fullclassname,
                                                  void* obj);

// this is the void pointer parm passed to the pgl callback routines on
// behalf of the Java interface for callbacks.
struct pglJavaVoidFuncArg 
{
  JavaVM *vm;
  jobject  uobj;
  jmethodID mid;
} ;

extern JNIEXPORT void pglJavaVoidFunc(void *);
extern JNIEXPORT void pglJavaVoidFuncArgDelete(void *);


#endif
