source: trunk/lang/perl/Rappture.xs @ 1716

Last change on this file since 1716 was 1716, checked in by mmc, 14 years ago

Fixed the Perl bindings to handle binary data properly. Users on vhub.org
stumbled into this. Image data was getting truncated on the first embedded
null byte, instead of keeping the entire length of the binary data.

File size: 2.0 KB
RevLine 
[665]1#include "rappture.h"
[481]2#include <string>
3
4#include "EXTERN.h"
5#include "perl.h"
6#include "XSUB.h"
7
8#include "ppport.h"
9
10using namespace std;
11
[1089]12MODULE = Rappture        PACKAGE = Rappture::RpLibrary
[481]13PROTOTYPES: ENABLE
14
15RpLibrary *
16RpLibrary::new(filename = "")
[1095]17const char *filename
[1089]18    CODE:
[481]19        RpLibrary *library;
[1089]20        if ((filename == NULL) || (*filename == '\0'))
21            library = new RpLibrary();
22        else
23            library = new RpLibrary(filename);
[481]24
[1089]25        if (library->isNull())
[481]26                {
27                        delete library;
[1089]28            XSRETURN_UNDEF;
[481]29                }
[1089]30        else
31            RETVAL = library;
32    OUTPUT:
33        RETVAL
[481]34
35void *
36RpLibrary::DESTROY()
[1089]37    CODE:
38        RETVAL = 0;
[481]39
[1716]40SV *
[481]41RpLibrary::get( path )
[1095]42const char *path
[1089]43    CODE:
44        string result;
45        result = THIS->get(path);
[1716]46        RETVAL = newSVpvn(result.data(),result.length());
[1089]47    OUTPUT:
48        RETVAL
[481]49
50void
51RpLibrary::put( path, value, append )
[1095]52const char *path
53const char *value
[481]54int append
[1089]55    CODE:
56        THIS->put(path,value,"",append);
[591]57
[481]58void
[605]59RpLibrary::putFile( path, fileName, compress, append )
[1095]60const char *path
61const char *fileName
[605]62int compress
[591]63int append
[1089]64    CODE:
65        THIS->putFile(path,fileName,compress,append);
[591]66
67void
[481]68RpLibrary::result()
[1089]69    CODE:
70        THIS->put("tool.version.rappture.language", "perl");
71        THIS->result();
[481]72
[1089]73MODULE = Rappture        PACKAGE = Rappture::RpUnits
[481]74
75const char *
76convert( fromVal, toUnitsName, showUnits = 1 )
77const char *fromVal
78const char *toUnitsName
79int showUnits
[1089]80    CODE:
81        string result;
82        result = RpUnits::convert(fromVal,toUnitsName,showUnits);
[481]83
84                if (result.empty())
85                    XSRETURN_UNDEF;
86
[1089]87        RETVAL = result.c_str();
88    OUTPUT:
89        RETVAL
[665]90
[1089]91MODULE = Rappture        PACKAGE = Rappture::Utils
[665]92
93int
94progress( percent, message )
95int percent
96const char *message
[1089]97    CODE:
98        RETVAL = Rappture::Utils::progress(percent,message);
99    OUTPUT:
100        RETVAL
Note: See TracBrowser for help on using the repository browser.