Autore Topic: Un paio di domande sulla creazione di applicazioni web / CGI  (Letto 580 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
« Ultima modifica: 14 Settembre 2015, 01:12:04 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Un paio di domande sulla creazione di applicazioni web / CGI
« Risposta #1 il: 14 Febbraio 2015, 00:24:35 »
...continua...


" If you're going to use a database to communicate between 2 separate
programs, be sure to set the transaction isolation to READ-COMITTED
(good for MySQL, ymmv), otherwise you won't see updates made by another
process which can lead to some frustrating and confusing mismatches
between what you think should be read from the database and what
actually gets read!

You may also want to look at in-memory databases, if you don't need the
sensor data to be persistent.  H2:
http://www.h2database.com/html/main.html and JavaDB:
http://docs.oracle.com/javadb/10.8.3.0/getstart/index.html
might be worth a look.  You could always use a regular database for the
less volatile data, like user settings etc. and I imagine the
inter-process communication would be easier to set up using a normal
disk-based database.

The architecture is sound, I use a raspberry pi in a similar way to
control my central heating.  There's a python script running all the
time checking for interrupts so you can hit a button on the pi (PiFace
board added) to, for example, force the heating on.  The python script
reads from the MySQL db to see what temperature it should be aiming for,
and reads a usb thermometer to see what the temperature actually is.
There's a web interface written in php with big friendly buttons to
force the heating on or off, and a nice display of the current
temperature and the target temperature, and an indication of the state
of the heating (on or off).  Inter-process communication is all done via
the heating database in MySQL (with tx-isolation as above!).

Sorry, kind of realised at the end this is a little off-topic for most
of the Gambas list, what if I promise to rewrite my web-interface in
Gambas CGI? :-)

Kind regards,
Caveat
"


" Caveat,

Thanks for the info.

I'm a little concerned about using a "disk" based database because the disk is flash, which has a limited number of write cycles.  Even with wear-leveling, I would eventually kill parts of the flash.  I don't want these things dropping dead in the field after a year or so...

I was considering something like named pipes, but I'm a little unclear about how Linux actually handles them.  I thought I saw a mention that they are managed via temporary files within the file system, and that would defeat the whole idea of not writing to disk.

I know how to do interprocess communication in Windows, but not in Linux with Gambas.

Bruce
"


" Bruce,

Named pipes do indeed require a node on the file system. You might need to look
into shared memory; or maybe DBUS might suit your needs.

Lee
"


" Forgive me for poking my nose in where my profound ignorance indicates I
should not but ....

Would not a direct solution be:
1) Have the resident program ALLOC a section of ram
2) Save the address as part of a unique file name (i.e. ADRxxxxxx.ADR
where xxxxx is the address)
3) Pass the required parameters back and forth via shared memory.
4) Both programs would need to poll the shared memory for updates (some
bytes could be used for status).

http://gambaswiki.org/wiki/lang/alloc
http://gambaswiki.org/wiki/lang/byte@
http://gambaswiki.org/wiki/lang/integer@
http://gambaswiki.org/wiki/lang/long@
http://gambaswiki.org/wiki/lang/string@
... etc ...


Cheers,

Lewis
"


" This is almost a solution. The only remaining problem is to actually share
the memory. If you allocate some memory in one process, another process
cannot see it. Indeed independent processes have distinct virtual address
spaces (unless they specifically arrange otherwise), so a pointer from one
process is of no use to another process. They live in (almost) entirely
different realms, address-space-wise.

Gambas does not include functionality to share memory, so you would be
doomed to use Extern, hack the interpreter or write a native component,
each of which requires some knowledge of C and Linux (or at least POSIX)
and *may* bother the other parts of the interpreter but I don't know, never
tried it.

A named pipe or a UNIX socket are easier ways here.

On Fri, 13 Feb 2015, T Lee Davidson wrote:
> Named pipes do indeed require a node on the file system.

While that's true, they only require a node on the *virtua* file system. No
physical disk is touched ever:

  $ man 7 fifo
  [...]
  When processes are exchanging data via the FIFO, the kernel passes all
  data internally without writing it to the filesystem.   Thus, the FIFO
  special file  has  no contents on the filesystem; the filesystem entry
  merely serves  as  a reference point  so that processes can access the
  pipe using a name in the filesystem.
  [...]

and luckily, Gambas has support for named pipes
http://gambaswiki.org/wiki/lang/pipe
or sockets
http://gambaswiki.org/wiki/comp/gb.net/

Regards,
Tobi
"
« Ultima modifica: 14 Febbraio 2015, 02:00:09 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Un paio di domande sulla creazione di applicazioni web / CGI
« Risposta #2 il: 14 Febbraio 2015, 16:02:41 »
...continua...

" Indeed!

One thing for linux "L"-platers to understand is that "everything is a file" ! :-)
Hence that is why Stream is the basis for "everything" in Gambas.

http://en.wikipedia.org/wiki/Everything_is_a_file
or from Google: https://www.google.com.au/search?q=linux+%22everything+is+a+file%22&ie=utf-8&oe=utf-8&gws_rd=cr&ei=9KXeVJKoC-W7mgW-7IKADQ

cheers
Bruce
"


" You can use a named pipe : you create the node on the disk once (if you
don't want to ruin the flash). All the data exchange will be done in
memory by the system.

Regards,

--
Benoît Minisini
"


" Hey Bruce,
In addition to all the good suggestions everyone is throwing in the
problem, you could use a CouchDB database on a different server and just
connect to it with a normal http connection if you're worried about file
hits on the sd card. Gambas supports JSON and the httpclient component
should work just fine for what you want it to do.

Hope this helps,
Dimitris
"


" Hey Bruce, have a look at this link for a anaolg gauge html server. \
RegardsMike
Gauges

|   |
|   |  |   |   |   |   |   |
| GaugesController Channel: Switch Cancel Status:  |
|  |
| View on demo.crossbar.io | Preview by Yahoo |
|  |
|   |

Bruce this is the link
Mike Gauges
https://demo.crossbar.io/demo/gauges/index.html
Regards
Mike
"
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »