[reduknoppix-dev] Re: [gr3p] working demo del wrapper

  • From: Daniele Menozzi <menoz@xxxxxx>
  • To: reduknoppix-dev@xxxxxxxxxxxxx
  • Date: Thu, 30 Jun 2005 12:32:47 +0200

 Ecco la mia prima patch. Ho implementato l'accensione e spegnimento delle
 due luci, ed aggiunto una funzione che trasforma un  ::java::lang::String* 
 in un RawDataManaged*
 Il procedimento per accendere e spegnere le luci fa un po schifo, ma
 funziona. Non ho idea se possa essere migliorato.

Intanto cmq guarda se riesci/ritieni\ opportuno fare il merge col tuo
codice, prima di buttarlo su cvs.

Ciao
        Menoz
 
-- 
                      Free Software Enthusiast
                 Debian Powered Linux User #332564 
                     http://shine.homelinux.org
diff -N3u gr3p-original-ax82/Gr3p.java gr3p/Gr3p.java
--- gr3p-original-ax82/Gr3p.java        2005-06-22 22:26:43.000000000 +0200
+++ gr3p/Gr3p.java      2005-06-30 11:00:00.000000000 +0200
@@ -38,6 +38,12 @@
       System.err.println(Qx3Model.getColour());
       Qx3Model.setBrightness(new Integer(args[4]).intValue());
       System.err.println(Qx3Model.getBrightness());
+
+      //menoz:mettere le seguenti 4 operazioni dopo il getframe NON le fa 
funzionare
+      boolean b = Qx3Model.getTopLight();
+      Qx3Model.setTopLight(!b);
+      b = Qx3Model.getBottomLight();
+      Qx3Model.setBottomLight(!b);
             
       byte[] byAr = Qx3Model.getFrame();
       System.err.println(byAr.length);
@@ -50,18 +56,11 @@
       }
       System.err.println(j);
   
-      /*
-      boolean b = Qx3Model.getTopLight();
-      Qx3Model.setTopLight(!b);
-  
-      b = Qx3Model.getBottomLight();
-      Qx3Model.setBottomLight(!b);
-      */
     }
     catch(UnsupportedOperationException uoe)
     {
       System.err.println(uoe);
-      System.err.println("wé, lo scrivi 'sto programma o no??");
+      System.err.println("oh, lo scrivi 'sto programma o no??");
     }
   }
 }
Binary files gr3p-original-ax82/.Gr3p.java.swp and gr3p/.Gr3p.java.swp differ
diff -N3u gr3p-original-ax82/Qx3Model-core.cc gr3p/Qx3Model-core.cc
--- gr3p-original-ax82/Qx3Model-core.cc 2005-06-22 22:41:08.000000000 +0200
+++ gr3p/Qx3Model-core.cc       2005-06-30 10:56:28.000000000 +0200
@@ -37,23 +37,27 @@
 #include <linux/videodev.h>
 
 // C++ headers
-// #include <iostream>
-// #include <fstream>
-// #include <strstream>
-// #include <string>
-
+#include <iostream>
+#include <fstream>
+#include <strstream>
+#include <string>
+
+
+// Converte una ::java::lang::String* in un RawDataManaged.
+::gnu::gcj::RawDataManaged*
+org::reduknoppix::gr3p::Qx3Model::convertString(::java::lang::String * s){
+       int i = JvGetStringUTFLength(s);
+       char * buf = (char *) JvAllocBytes((jsize) i+1);
+       JvGetStringUTFRegion (s, 0, i, buf);
+       buf[i+1]='\0';
+       return (::gnu::gcj::RawDataManaged *) buf;
+}
 
-void
+       
+void 
 org::reduknoppix::gr3p::Qx3Model::setDevFile (::java::lang::String 
*devFileName)
 {
-  int i = JvGetStringUTFLength(devFileName);
-#ifdef DEBUG
-  fprintf(stderr,"Number of characters for Qx3Model::devFileC: %d\n", i);
-#endif
-  char * buf = (char *) JvAllocBytes((jsize) i+1);
-  JvGetStringUTFRegion (devFileName, 0, i, buf);
-  buf[i+1]='\0';
-  devFileC=(::gnu::gcj::RawDataManaged *) buf;
+  devFileC=convertString(devFileName); 
 #ifdef DEBUG
   fprintf(stderr,"Qx3Model::devFileC: %s\n", (char *) devFileC);
 #endif
@@ -64,14 +68,7 @@
 void
 org::reduknoppix::gr3p::Qx3Model::setCpiaFile (::java::lang::String 
*cpiaFileName)
 {
-  int i = JvGetStringUTFLength(cpiaFileName);
-#ifdef DEBUG
-  fprintf(stderr,"Number of characters for Qx3Model::devCpiaC: %d\n", i);
-#endif
-  char * buf = (char *) JvAllocBytes((jsize) i+1);
-  JvGetStringUTFRegion (cpiaFileName, 0, i, buf);
-  buf[i+1]='\0';
-  cpiaFileC=(::gnu::gcj::RawDataManaged *) buf;
+  cpiaFileC=convertString(cpiaFileName);
 #ifdef DEBUG
   fprintf(stderr,"Qx3Model::cpiaFileC: %s\n", (char *) cpiaFileC);
 #endif
@@ -119,14 +116,50 @@
 jboolean
 org::reduknoppix::gr3p::Qx3Model::getLight (::java::lang::String * whichLight)
 {
-  throw new ::java::lang::UnsupportedOperationException (JvNewStringLatin1 
("org::reduknoppix::gr3p::Qx3Model::getLight (::java::lang::String *) not 
implemented"));
+       std::string cpiaFileS= (const char *)cpiaFileC;
+       ::gnu::gcj::RawDataManaged* whichLightC=convertString(whichLight);
+  
+        std::ifstream from(cpiaFileS.data());
+        char line[BUF_LINE];
+        jboolean found = false;
+        std::string top,val;
+        while( !from.eof()) {
+                from.getline(line, BUF_LINE);
+               std::string strline(line);
+                if(strline.find((const char *)whichLightC, 0) != 
std::string::npos) {
+                        std::istrstream parsline( line ); 
+                        parsline >> top >> val; 
+                 
+                        if( val == "on" ) {
+                                found = true; 
+                        }       
+                }       
+        }       
+        from.close();
+       #ifdef DEBUG
+       fprintf(stderr, "La luce %s e' ",(const char *)whichLightC);
+       found?fprintf(stderr, "accesa\n"):fprintf(stderr, "spenta\n");
+       #endif
+        return found;
+
+  //throw new ::java::lang::UnsupportedOperationException (JvNewStringLatin1 
("org::reduknoppix::gr3p::Qx3Model::getLight (::java::lang::String *) not 
implemented"));
 }
 
 
 void
 org::reduknoppix::gr3p::Qx3Model::setLight (::java::lang::String * whichLight, 
jboolean status)
 {
-  throw new ::java::lang::UnsupportedOperationException (JvNewStringLatin1 
("org::reduknoppix::gr3p::Qx3Model::setLight (::java::lang::String *, jboolean) 
not implemented"));
+       ::gnu::gcj::RawDataManaged* whichLightC=convertString(whichLight);
+       std::string cpiaFile=(const char *)cpiaFileC;
+        std::ofstream to(cpiaFile.data());
+        to << (const char *)whichLightC << ": " << (status ? "on":"off") << 
std::endl;
+        to.close();
+       #ifdef DEBUG
+       status?fprintf(stderr, "Ho acceso "):fprintf(stderr, "Ho spento ");
+       fprintf(stderr, "la luce %s\n",(const char *)whichLightC);
+       #endif
+
+//  throw new ::java::lang::UnsupportedOperationException (JvNewStringLatin1 
("org::reduknoppix::gr3p::Qx3Model::setLight (::java::lang::String *, jboolean) 
not implemented"));
 }
 
 
Binary files gr3p-original-ax82/.Qx3Model-core.cc.swp and 
gr3p/.Qx3Model-core.cc.swp differ
diff -N3u gr3p-original-ax82/Qx3Model.java gr3p/Qx3Model.java
--- gr3p-original-ax82/Qx3Model.java    2005-06-22 22:49:46.000000000 +0200
+++ gr3p/Qx3Model.java  2005-06-30 01:21:57.000000000 +0200
@@ -33,6 +33,7 @@
 
   // ax82: credo che "synchronized" non funzioni coi metodi nativi, ma devo 
rileggere il manuale
   // TODO: testa
+  private static synchronized native RawDataManaged convertString(String s);
   private static synchronized native void setDevFile(String devFileName);
   private static synchronized native void setCpiaFile(String cpiaFileName);
   private static synchronized native boolean getLight(String whichLight);

Other related posts: