こんにちは私はブローカーのようなIOサーバーを構築する必要があります。
Webサーバーは、サーバー(ブローカー)と通信して、制御可能なデバイスなどの要求を行います。例えば。組み込みシステム..rs232またはusbとイーサネットを介してサーバーに接続されています。
たとえば、WebサーバーはデバイスAと通信し、Xを実行するように要求します。
サーバー(ブローカー)もデバイスと通信します。デバイスが起動すると、ブローカーに登録されます。私はデバイスbで、名前はkです。コマンドを実行する準備ができています。
私はdebianlinuxを使用していますが、これをどのように利用できるかを理解する必要があります。
これにはカーネルデバイスを作成する必要がありますか?
どうもありがとう。
編集:デーモンプログラミングについては、 http://www.netzmafia.de/skripten/unix/linux-daemon-howto.htmlで読んだばかりです。ここにコードをコピーして貼り付けました。
コードのどの部分を変更するかについてコメントを書き留めました。
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
int main(void) { // change this to "int main(int argc,char *argv[])"
/* Our process ID and Session ID */
pid_t pid, sid;
/* Fork off the parent process */
pid = fork();
if (pid < 0) {
exit(EXIT_FAILURE);
}
/* If we got a good PID, then
we can exit the parent process. */
if (pid > 0) {
exit(EXIT_SUCCESS);
}
/* Change the file mode mask */
umask(0);
/* Open any logs here */
/* Create a new SID for the child process */
sid = setsid();
if (sid < 0) {
/* Log the failure */
exit(EXIT_FAILURE);
}
/* Change the current working directory */
if ((chdir("/")) < 0) {
/* Log the failure */
exit(EXIT_FAILURE);
}
/* Close out the standard file descriptors */
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
/* Daemon-specific initialization goes here */
/* The Big Loop */
while (1) {
/* Do some task here ... */ // Device detect here. eg(/dev/ttyS0-usb-serial)
sleep(30); /* wait 30 seconds */ // Instead of using 30 seconds here I plan on removing it and changing it with events like wake up when new device is plugged.
}
exit(EXIT_SUCCESS);
}
このコード
int main(void)
これに変更
int main(int argc,char *argv[])
だから私はdebianのコマンドラインからコマンドを送ることができます。
このコードをwhileループ内に追加します-大きなループ
if(strcmp(argv[1], "status")==0){
//check status of devices here
}
if(new Device plugged){ // not real code. just to get the idea.
// register the device type and name.
}
次に、phpでshell_exec()を使用します。
<?php $output = shell_exec('daemon status'); echo "$output"; die;
phpのサンプル出力は次のようになります。
Device Name | Status
/dev/ttyS0 = online
/dev/sample = offline
私が考えていることは実行可能ですか?