metalsvm/kernel/shell.c
Carl-Benedikt Krüger c6c5cb29a7 shell test
2011-07-12 15:16:54 +02:00

72 lines
1.6 KiB
C

#include "shell.h"
#include "server.h"
#include "client.h"
#include <metalsvm/time.h>
static Server srv;
static int emac_id = -1;
static Client cli;
static int iamsrv = 0;
#include <metalsvm/stdio.h>
void shelldebugprintf(char* x,...)
{
if (iamsrv)
srv_sendBuffer(&srv,emac_id,x,strlen(x));
else
cli_sendBuffer(&cli,x,strlen(x));
}
void shell_on_connect(ServerEventArgs* e)
{
if (srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr > 0xC0A80031 || srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr < 0xC0A80001)
emac_id = e->ClientID;
kprintf("link engaged\n");
}
void shell_on_disconnect(ServerEventArgs* e)
{
kprintf("connection lost from %s:%d",inet_ntoa(srv.ConnectionsAddr[e->ClientID].sin_addr),ntohs(srv.ConnectionsAddr[e->ClientID].sin_port));
}
void shell_on_read(ServerEventArgs* e)
{
if (emac_id != -1 && e->ClientID != emac_id)
srv_sendBuffer(&srv,emac_id,e->pBuffer,e->dwLen);
// else commandos oder so
}
void shell_init(int srv_or_cli)
{
if (!srv_or_cli)
{
iamsrv = 1;
kprintf("server init");
server_init(&srv,5555,49);
srv._OnConnect = shell_on_connect;
srv._OnDisconnect = shell_on_disconnect;
srv._OnRead = shell_on_read;
}
else
{
sleep(3);
kprintf("client init");
cli_init(&cli);
while (cli_ConnectTo(&cli,"192.168.0.1",5555,0));
sleep(1);
sleep(5);
shelldebugprintf("sleeped 5 seconds\n");
sleep(5);
shelldebugprintf("sleeped another 5 seconds\n");
}
}