Style cleanup patch by Vasilis Kaoutsis. Small changes by myself.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22629 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2007-10-20 20:40:09 +00:00
parent cb93a65449
commit 9d3f15c60e
10 changed files with 1623 additions and 1713 deletions
File diff suppressed because it is too large Load Diff
+89 -103
View File
@@ -1,20 +1,22 @@
/* CodyCam.h */ /* CodyCam.h */
#ifndef CODYCAM_H #ifndef CODYCAM_H
#define CODYCAM_H #define CODYCAM_H
#include <Box.h>
#include <Menu.h>
#include <string.h>
#include <Window.h>
#include <CheckBox.h>
#include <MenuField.h>
#include <StringView.h>
#include <Application.h>
#include <TextControl.h>
#include "Settings.h" #include "Settings.h"
#include"VideoConsumer.h" #include "VideoConsumer.h"
#include <string.h>
#include <Application.h>
#include <Box.h>
#include <CheckBox.h>
#include <Menu.h>
#include <MenuField.h>
#include <StringView.h>
#include <TextControl.h>
#include <Window.h>
class BMediaRoster; class BMediaRoster;
@@ -56,7 +58,8 @@ enum {
msg_control_win = 'ctlw' msg_control_win = 'ctlw'
}; };
const char *kCaptureRate[] = {
const char* kCaptureRate[] = {
"Every 15 seconds", "Every 15 seconds",
"Every 30 seconds", "Every 30 seconds",
"Every minute", "Every minute",
@@ -73,113 +76,96 @@ const char *kCaptureRate[] = {
0 0
}; };
class CodyCam : public BApplication { class CodyCam : public BApplication {
public: public:
CodyCam(); CodyCam();
virtual ~CodyCam(); virtual ~CodyCam();
void ReadyToRun(); void ReadyToRun();
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MessageReceived( virtual void MessageReceived(BMessage* message);
BMessage *message);
private: private:
status_t SetUpNodes(); status_t _SetUpNodes();
void TearDownNodes(); void _TearDownNodes();
BMediaRoster * fMediaRoster;
media_node fTimeSourceNode; BMediaRoster* fMediaRoster;
media_node fProducerNode; media_node fTimeSourceNode;
media_node fProducerNode;
VideoConsumer * fVideoConsumer; VideoConsumer* fVideoConsumer;
media_output fProducerOut;
media_output fProducerOut; media_input fConsumerIn;
media_input fConsumerIn; BWindow* fWindow;
port_id fPort;
BWindow * fWindow; BWindow* fVideoControlWindow;
port_id fPort;
BWindow *mVideoControlWindow;
}; };
class VideoWindow : public BWindow
{
public:
VideoWindow (
BRect frame,
const char * title,
window_type type,
uint32 flags,
port_id * consumerport);
~VideoWindow();
virtual bool QuitRequested(); class VideoWindow : public BWindow {
virtual void MessageReceived( public:
BMessage *message); VideoWindow(BRect frame, const char* title, window_type type,
uint32 flags, port_id* consumerport);
~VideoWindow();
void ApplyControls(); virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message);
BView * VideoView();
BStringView * StatusLine();
private:
void BuildCaptureControls(
BView *theView);
void SetUpSettings( void ApplyControls();
const char *filename,
const char *dirname);
void QuitSettings();
private: BView* VideoView();
media_node * fProducer; BStringView* StatusLine();
port_id * fPortPtr;
BView * fView;
BView * fVideoView;
BTextControl * fFileName;
BBox * fCaptureSetupBox;
BMenu * fCaptureRateMenu;
BMenuField * fCaptureRateSelector;
BMenu * fImageFormatMenu;
BMenuField * fImageFormatSelector;
BBox * fFtpSetupBox;
BTextControl * fServerName;
BTextControl * fLoginId;
BTextControl * fPassword;
BTextControl * fDirectory;
BCheckBox * fPassiveFtp;
BBox * fStatusBox;
BStringView * fStatusLine;
ftp_msg_info fFtpInfo;
Settings * fSettings; private:
StringValueSetting * fServerSetting; void _BuildCaptureControls(BView* theView);
StringValueSetting * fLoginSetting;
StringValueSetting * fPasswordSetting; void _SetUpSettings(const char* filename, const char* dirname);
StringValueSetting * fDirectorySetting; void _QuitSettings();
BooleanValueSetting * fPassiveFtpSetting;
StringValueSetting * fFilenameSetting; private:
EnumeratedStringValueSetting *fCaptureRateSetting; media_node* fProducer;
port_id* fPortPtr;
BView* fView;
BView* fVideoView;
BTextControl* fFileName;
BBox* fCaptureSetupBox;
BMenu* fCaptureRateMenu;
BMenuField* fCaptureRateSelector;
BMenu* fImageFormatMenu;
BMenuField* fImageFormatSelector;
BBox* fFtpSetupBox;
BTextControl* fServerName;
BTextControl* fLoginId;
BTextControl* fPassword;
BTextControl* fDirectory;
BCheckBox* fPassiveFtp;
BBox* fStatusBox;
BStringView* fStatusLine;
ftp_msg_info fFtpInfo;
Settings* fSettings;
StringValueSetting* fServerSetting;
StringValueSetting* fLoginSetting;
StringValueSetting* fPasswordSetting;
StringValueSetting* fDirectorySetting;
BooleanValueSetting* fPassiveFtpSetting;
StringValueSetting* fFilenameSetting;
EnumeratedStringValueSetting* fCaptureRateSetting;
}; };
class ControlWindow : public BWindow { class ControlWindow : public BWindow {
public:
public: ControlWindow(const BRect& frame, BView* controls, media_node node);
ControlWindow(const BRect & frame, BView * controls, media_node node); void MessageReceived(BMessage* message);
void MessageReceived(BMessage * message);
bool QuitRequested(); bool QuitRequested();
private: private:
BView * fView; BView* fView;
media_node fNode; media_node fNode;
}; };
#endif #endif // CODYCAM_H
+276 -372
View File
@@ -1,38 +1,36 @@
#include "FtpClient.h" #include "FtpClient.h"
FtpClient::FtpClient() FtpClient::FtpClient()
:
fState(0),
fControl(NULL),
fData(NULL)
{ {
m_control = 0;
m_state = 0;
m_data = 0;
} }
FtpClient::~FtpClient() FtpClient::~FtpClient()
{ {
delete m_control; delete fControl;
delete m_data; delete fData;
} }
bool FtpClient::cd(const string &dir) bool
FtpClient::ChangeDir(const string& dir)
{ {
bool rc = false; bool rc = false;
int code, codetype; int code, codeType;
string cmd = "CWD ", replystr; string cmd = "CWD ", replyString;
cmd += dir; cmd += dir;
if(dir.length() == 0) if (dir.length() == 0)
cmd += '/'; cmd += '/';
if(p_sendRequest(cmd) == true) if (_SendRequest(cmd) == true) {
{ if (_GetReply(replyString, code, codeType) == true) {
if(p_getReply(replystr, code, codetype) == true) if (codeType == 2)
{
if(codetype == 2)
rc = true; rc = true;
} }
} }
@@ -40,44 +38,36 @@ bool FtpClient::cd(const string &dir)
} }
bool FtpClient::ls(string &listing) bool
FtpClient::ListDirContents(string& listing)
{ {
bool rc = false; bool rc = false;
string cmd, replystr; string cmd, replyString;
int code, codetype, numread; int code, codeType, numRead;
char buf[513]; char buf[513];
cmd = "TYPE A"; cmd = "TYPE A";
if(p_sendRequest(cmd)) if (_SendRequest(cmd))
p_getReply(replystr, code, codetype); _GetReply(replyString, code, codeType);
if(p_openDataConnection()) if (_OpenDataConnection()) {
{
cmd = "LIST"; cmd = "LIST";
if(p_sendRequest(cmd)) if (_SendRequest(cmd)) {
{ if (_GetReply(replyString, code, codeType)) {
if(p_getReply(replystr, code, codetype)) if (codeType <= 2) {
{ if (_AcceptDataConnection()) {
if(codetype <= 2) numRead = 1;
{ while (numRead > 0) {
if(p_acceptDataConnection())
{
numread = 1;
while(numread > 0)
{
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
numread = m_data->Receive(buf, sizeof(buf) - 1); numRead = fData->Receive(buf, sizeof(buf) - 1);
listing += buf; listing += buf;
printf(buf); printf(buf);
} }
if(p_getReply(replystr, code, codetype)) if (_GetReply(replyString, code, codeType)) {
{ if (codeType <= 2)
if(codetype <= 2)
{
rc = true; rc = true;
}
} }
} }
} }
@@ -85,31 +75,28 @@ bool FtpClient::ls(string &listing)
} }
} }
delete m_data; delete fData;
m_data = 0; fData = 0;
return rc; return rc;
} }
bool FtpClient::pwd(string &dir) bool
FtpClient::PrintWorkingDir(string& dir)
{ {
bool rc = false; bool rc = false;
int code, codetype; int code, codeType;
string cmd = "PWD", replystr; string cmd = "PWD", replyString;
long i; long i;
if(p_sendRequest(cmd) == true) if (_SendRequest(cmd) == true) {
{ if (_GetReply(replyString, code, codeType) == true) {
if(p_getReply(replystr, code, codetype) == true) if (codeType == 2) {
{ i = replyString.find('"');
if(codetype == 2) if (i != -1) {
{
i = replystr.find('"');
if(i != -1)
{
i++; i++;
dir = replystr.substr(i, replystr.find('"') - i); dir = replyString.substr(i, replyString.find('"') - i);
rc = true; rc = true;
} }
} }
@@ -120,129 +107,110 @@ bool FtpClient::pwd(string &dir)
} }
bool FtpClient::connect(const string &server, const string &login, const string &passwd) bool
FtpClient::Connect(const string& server, const string& login, const string& passwd)
{ {
bool rc = false; bool rc = false;
int code, codetype; int code, codeType;
string cmd, replystr; string cmd, replyString;
BNetAddress addr; BNetAddress addr;
delete m_control; delete fControl;
delete m_data; delete fData;
fControl = new BNetEndpoint;
m_control = new BNetEndpoint;
if (fControl->InitCheck() != B_NO_ERROR)
if(m_control->InitCheck() != B_NO_ERROR)
return false; return false;
addr.SetTo(server.c_str(), "tcp", "ftp"); addr.SetTo(server.c_str(), "tcp", "ftp");
if(m_control->Connect(addr) == B_NO_ERROR) if (fControl->Connect(addr) == B_NO_ERROR) {
{
//
// read the welcome message, do the login // read the welcome message, do the login
//
if(p_getReply(replystr, code, codetype)) if (_GetReply(replyString, code, codeType)) {
{ if (code != 421 && codeType != 5) {
if(code != 421 && codetype != 5) cmd = "USER ";
{ cmd += login;
cmd = "USER "; cmd += login; _SendRequest(cmd);
p_sendRequest(cmd);
if(p_getReply(replystr, code, codetype)) if (_GetReply(replyString, code, codeType)) {
{ switch (code) {
switch(code)
{
case 230: case 230:
case 202: case 202:
rc = true; rc = true;
break; break;
case 331: // password needed case 331: // password needed
cmd = "PASS "; cmd += passwd; cmd = "PASS ";
p_sendRequest(cmd); cmd += passwd;
if(p_getReply(replystr, code, codetype)) _SendRequest(cmd);
{ if (_GetReply(replyString, code, codeType)) {
if(codetype == 2) if (codeType == 2)
{
rc = true; rc = true;
}
} }
break; break;
default: default:
break; break;
} }
} }
} }
} }
} }
if(rc == true)
{
p_setState(ftp_connected);
} else { if (rc == true)
delete m_control; _SetState(ftp_connected);
m_control = 0; else {
delete fControl;
fControl = 0;
} }
return rc; return rc;
} }
bool
bool FtpClient::putFile(const string &local, const string &remote, ftp_mode mode) FtpClient::PutFile(const string& local, const string& remote, ftp_mode mode)
{ {
bool rc = false; bool rc = false;
string cmd, replystr; string cmd, replyString;
int code, codetype, rlen, slen, i; int code, codeType, rlen, slen, i;
BFile infile(local.c_str(), B_READ_ONLY); BFile infile(local.c_str(), B_READ_ONLY);
char buf[8192], sbuf[16384], *stmp; char buf[8192], sbuf[16384], *stmp;
if(infile.InitCheck() != B_NO_ERROR) if (infile.InitCheck() != B_NO_ERROR)
return false; return false;
if(mode == binary_mode) if (mode == binary_mode)
cmd = "TYPE I"; cmd = "TYPE I";
else else
cmd = "TYPE A"; cmd = "TYPE A";
if(p_sendRequest(cmd)) if (_SendRequest(cmd))
p_getReply(replystr, code, codetype); _GetReply(replyString, code, codeType);
try try {
{ if (_OpenDataConnection()) {
if(p_openDataConnection())
{
cmd = "STOR "; cmd = "STOR ";
cmd += remote; cmd += remote;
if(p_sendRequest(cmd)) if (_SendRequest(cmd)) {
{ if (_GetReply(replyString, code, codeType)) {
if(p_getReply(replystr, code, codetype)) if (codeType <= 2) {
{ if (_AcceptDataConnection()) {
if(codetype <= 2)
{
if(p_acceptDataConnection())
{
rlen = 1; rlen = 1;
while(rlen > 0) while (rlen > 0) {
{
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
memset(sbuf, 0, sizeof(sbuf)); memset(sbuf, 0, sizeof(sbuf));
rlen = infile.Read((void *) buf, sizeof(buf)); rlen = infile.Read((void*)buf, sizeof(buf));
slen = rlen; slen = rlen;
stmp = buf; stmp = buf;
if(mode == ascii_mode) if (mode == ascii_mode) {
{
stmp = sbuf; stmp = sbuf;
slen = 0; slen = 0;
for(i=0;i<rlen;i++) for (i = 0; i < rlen; i++) {
{ if (buf[i] == '\n') {
if(buf[i] == '\n')
{
*stmp = '\r'; *stmp = '\r';
stmp++; stmp++;
slen++; slen++;
@@ -253,9 +221,8 @@ bool FtpClient::putFile(const string &local, const string &remote, ftp_mode mode
} }
stmp = sbuf; stmp = sbuf;
} }
if(slen > 0) if (slen > 0) {
{ if (fData->Send(stmp, slen) < 0)
if(m_data->Send(stmp, slen) < 0)
throw "bail"; throw "bail";
} }
} }
@@ -267,143 +234,119 @@ bool FtpClient::putFile(const string &local, const string &remote, ftp_mode mode
} }
} }
} }
catch(const char *errstr) catch(const char* errorString)
{ {
}
delete fData;
fData = 0;
if (rc) {
_GetReply(replyString, code, codeType);
rc = codeType <= 2;
} }
delete m_data;
m_data = 0;
if(rc == true)
{
p_getReply(replystr, code, codetype);
rc = (bool) codetype <= 2;
}
return rc; return rc;
} }
bool
bool FtpClient::getFile(const string &remote, const string &local, ftp_mode mode) FtpClient::GetFile(const string& remote, const string& local, ftp_mode mode)
{ {
bool rc = false; bool rc = false;
string cmd, replystr; string cmd, replyString;
int code, codetype, rlen, slen, i; int code, codeType, rlen, slen, i;
BFile outfile(local.c_str(), B_READ_WRITE | B_CREATE_FILE); BFile outfile(local.c_str(), B_READ_WRITE | B_CREATE_FILE);
char buf[8192], sbuf[16384], *stmp; char buf[8192], sbuf[16384], *stmp;
bool writeerr = false; bool writeError = false;
if(outfile.InitCheck() != B_NO_ERROR) if (outfile.InitCheck() != B_NO_ERROR)
return false; return false;
if(mode == binary_mode) if (mode == binary_mode)
cmd = "TYPE I"; cmd = "TYPE I";
else else
cmd = "TYPE A"; cmd = "TYPE A";
if(p_sendRequest(cmd))
p_getReply(replystr, code, codetype);
if (_SendRequest(cmd))
if(p_openDataConnection()) _GetReply(replyString, code, codeType);
{
if (_OpenDataConnection()) {
cmd = "RETR "; cmd = "RETR ";
cmd += remote; cmd += remote;
if(p_sendRequest(cmd)) if (_SendRequest(cmd)) {
{ if (_GetReply(replyString, code, codeType)) {
if(p_getReply(replystr, code, codetype)) if (codeType <= 2) {
{ if (_AcceptDataConnection()) {
if(codetype <= 2)
{
if(p_acceptDataConnection())
{
rlen = 1; rlen = 1;
rc = true; rc = true;
while(rlen > 0) while (rlen > 0) {
{
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
memset(sbuf, 0, sizeof(sbuf)); memset(sbuf, 0, sizeof(sbuf));
rlen = m_data->Receive(buf, sizeof(buf)); rlen = fData->Receive(buf, sizeof(buf));
if(rlen > 0) if (rlen > 0) {
{
slen = rlen; slen = rlen;
stmp = buf; stmp = buf;
if(mode == ascii_mode) if (mode == ascii_mode) {
{
stmp = sbuf; stmp = sbuf;
slen = 0; slen = 0;
for(i=0;i<rlen;i++) for (i = 0; i < rlen; i++) {
{ if (buf[i] == '\r')
if(buf[i] == '\r')
{
i++; i++;
}
*stmp = buf[i]; *stmp = buf[i];
stmp++; stmp++;
slen++; slen++;
} }
stmp = sbuf; stmp = sbuf;
} }
if(slen > 0) if (slen > 0) {
{ if (outfile.Write(stmp, slen) < 0)
if(outfile.Write(stmp, slen) < 0) writeError = true;
{
writeerr = true;
}
} }
} }
} }
} }
} }
} }
} }
} }
delete fData;
fData = 0;
delete m_data; if (rc) {
m_data = 0; _GetReply(replyString, code, codeType);
rc = (codeType <= 2 && writeError == false);
if(rc == true) }
{
p_getReply(replystr, code, codetype);
rc = (bool) ((codetype <= 2) && (writeerr == false));
}
return rc; return rc;
} }
//
// Note: this only works for local remote moves, cross filesystem moves // Note: this only works for local remote moves, cross filesystem moves
// will not work // will not work
// bool
bool FtpClient::moveFile(const string &oldpath, const string &newpath) FtpClient::MoveFile(const string& oldPath, const string& newPath)
{ {
bool rc = false; bool rc = false;
string from = "RNFR "; string from = "RNFR ";
string to = "RNTO "; string to = "RNTO ";
string replystr; string replyString;
int code, codetype; int code, codeType;
from += oldpath; from += oldPath;
to += newpath; to += newPath;
if(p_sendRequest(from)) if (_SendRequest(from)) {
{ if (_GetReply(replyString, code, codeType)) {
if(p_getReply(replystr, code, codetype)) if (codeType == 3) {
{ if (_SendRequest(to)) {
if(codetype == 3) if (_GetReply(replyString, code, codeType)) {
{ if(codeType == 2)
if(p_sendRequest(to))
{
if(p_getReply(replystr, code, codetype))
{
if(codetype == 2)
rc = true; rc = true;
} }
} }
@@ -414,62 +357,60 @@ bool FtpClient::moveFile(const string &oldpath, const string &newpath)
} }
void FtpClient::setPassive(bool on) void
FtpClient::SetPassive(bool on)
{ {
if(on) if (on)
p_setState(ftp_passive); _SetState(ftp_passive);
else else
p_clearState(ftp_passive); _ClearState(ftp_passive);
} }
bool
bool FtpClient::p_testState(unsigned long state) FtpClient::_TestState(unsigned long state)
{ {
return (bool) ((m_state & state) != 0); return ((fState & state) != 0);
} }
void
void FtpClient::p_setState(unsigned long state) FtpClient::_SetState(unsigned long state)
{ {
m_state |= state; fState |= state;
} }
void
void FtpClient::p_clearState(unsigned long state) FtpClient::_ClearState(unsigned long state)
{ {
m_state &= ~state; fState &= ~state;
} }
bool
FtpClient::_SendRequest(const string& cmd)
bool FtpClient::p_sendRequest(const string &cmd)
{ {
bool rc = false; bool rc = false;
string ccmd = cmd; string ccmd = cmd;
if(m_control != 0) if (fControl != 0) {
{ if (cmd.find("PASS") != string::npos)
if(cmd.find("PASS") != string::npos)
printf("PASS <suppressed> (real password sent)\n"); printf("PASS <suppressed> (real password sent)\n");
else else
printf("%s\n", ccmd.c_str()); printf("%s\n", ccmd.c_str());
ccmd += "\r\n"; ccmd += "\r\n";
if(m_control->Send(ccmd.c_str(), ccmd.length()) >= 0) if (fControl->Send(ccmd.c_str(), ccmd.length()) >= 0)
{
rc = true; rc = true;
}
} }
return rc; return rc;
} }
bool
bool FtpClient::p_getReplyLine(string &line) FtpClient::_GetReplyLine(string& line)
{ {
bool rc = false; bool rc = false;
int c = 0; int c = 0;
@@ -477,38 +418,33 @@ bool FtpClient::p_getReplyLine(string &line)
line = ""; // Thanks to Stephen van Egmond for catching a bug here line = ""; // Thanks to Stephen van Egmond for catching a bug here
if(m_control != 0) if (fControl != 0) {
{
rc = true; rc = true;
while(done == false && (m_control->Receive(&c, 1) > 0)) while (done == false && fControl->Receive(&c, 1) > 0) {
{ if (c == EOF || c == xEOF || c == '\n') {
if(c == EOF || c == xEOF || c == '\n')
{
done = true; done = true;
} else { } else {
if(c == IAC) if (c == IAC) {
{ fControl->Receive(&c, 1);
m_control->Receive(&c, 1); switch (c) {
switch(c)
{
unsigned char treply[3]; unsigned char treply[3];
case WILL: case WILL:
case WONT: case WONT:
m_control->Receive(&c, 1); fControl->Receive(&c, 1);
treply[0] = IAC; treply[0] = IAC;
treply[1] = DONT; treply[1] = DONT;
treply[2] = c; treply[2] = c;
m_control->Send(treply, 3); fControl->Send(treply, 3);
break; break;
case DO: case DO:
case DONT: case DONT:
m_control->Receive(&c, 1); fControl->Receive(&c, 1);
m_control->Receive(&c, 1); fControl->Receive(&c, 1);
treply[0] = IAC; treply[0] = IAC;
treply[1] = WONT; treply[1] = WONT;
treply[2] = c; treply[2] = c;
m_control->Send(treply, 3); fControl->Send(treply, 3);
break; break;
case EOF: case EOF:
@@ -521,10 +457,8 @@ bool FtpClient::p_getReplyLine(string &line)
break; break;
} }
} else { } else {
//
// normal char // normal char
// if (c != '\r')
if(c != '\r')
line += c; line += c;
} }
} }
@@ -535,10 +469,11 @@ bool FtpClient::p_getReplyLine(string &line)
} }
bool FtpClient::p_getReply(string &outstr, int &outcode, int &codetype) bool
FtpClient::_GetReply(string& outString, int& outCode, int& codeType)
{ {
bool rc = false; bool rc = false;
string line, tempstr; string line, tempString;
// //
// comment from the ncftp source: // comment from the ncftp source:
@@ -556,149 +491,125 @@ bool FtpClient::p_getReply(string &outstr, int &outcode, int &codetype)
* 234 A line beginning with numbers * 234 A line beginning with numbers
* 123 The last line * 123 The last line
*/ */
if((rc = p_getReplyLine(line)) == true) if ((rc = _GetReplyLine(line)) == true) {
{ outString = line;
outstr = line; outString += '\n';
outstr += '\n'; printf(outString.c_str());
printf(outstr.c_str()); tempString = line.substr(0, 3);
tempstr = line.substr(0, 3); outCode = atoi(tempString.c_str());
outcode = atoi(tempstr.c_str());
if(line[3] == '-') if (line[3] == '-') {
{ while ((rc = _GetReplyLine(line)) == true) {
while((rc = p_getReplyLine(line)) == true) outString += line;
{ outString += '\n';
outstr += line; printf(outString.c_str());
outstr += '\n';
printf(outstr.c_str());
//
// we're done with nnn when we get to a "nnn blahblahblah" // we're done with nnn when we get to a "nnn blahblahblah"
// if ((line.find(tempString) == 0) && line[3] == ' ')
if((line.find(tempstr) == 0) && line[3] == ' ')
break; break;
} }
} }
} }
if(rc == false && outcode != 421) if (!rc && outCode != 421) {
{ outString += "Remote host has closed the connection.\n";
outstr += "Remote host has closed the connection.\n"; outCode = 421;
outcode = 421;
} }
if(outcode == 421) if (outCode == 421) {
{ delete fControl;
delete m_control; fControl = 0;
m_control = 0; _ClearState(ftp_connected);
p_clearState(ftp_connected);
} }
codetype = outcode / 100; codeType = outCode / 100;
return rc; return rc;
} }
bool
bool FtpClient::p_openDataConnection() FtpClient::_OpenDataConnection()
{ {
string host, cmd, repstr; string host, cmd, replyString;
unsigned short port; unsigned short port;
BNetAddress addr; BNetAddress addr;
int i, code, codetype; int i, code, codeType;
bool rc = false; bool rc = false;
struct sockaddr_in sa; struct sockaddr_in sa;
delete m_data; delete fData;
m_data = 0; fData = 0;
m_data = new BNetEndpoint; fData = new BNetEndpoint;
if(p_testState(ftp_passive)) if (_TestState(ftp_passive)) {
{
//
// Here we send a "pasv" command and connect to the remote server // Here we send a "pasv" command and connect to the remote server
// on the port it sends back to us // on the port it sends back to us
//
cmd = "PASV"; cmd = "PASV";
if(p_sendRequest(cmd)) if (_SendRequest(cmd)) {
{ if (_GetReply(replyString, code, codeType)) {
if(p_getReply(repstr, code, codetype))
{ if (codeType == 2) {
if(codetype == 2)
{
// It should give us something like: // It should give us something like:
// "227 Entering Passive Mode (192,168,1,1,10,187)" // "227 Entering Passive Mode (192,168,1,1,10,187)"
int paddr[6]; int paddr[6];
unsigned char ucaddr[6]; unsigned char ucaddr[6];
i = repstr.find('('); i = replyString.find('(');
i++; i++;
repstr = repstr.substr(i, repstr.find(')') - i); replyString = replyString.substr(i, replyString.find(')') - i);
if (sscanf(repstr.c_str(), "%d,%d,%d,%d,%d,%d", if (sscanf(replyString.c_str(), "%d,%d,%d,%d,%d,%d",
&paddr[0], &paddr[1], &paddr[2], &paddr[3], &paddr[0], &paddr[1], &paddr[2], &paddr[3],
&paddr[4], &paddr[5]) != 6) &paddr[4], &paddr[5]) != 6) {
{ // cannot do passive. Do a little harmless rercursion here
// _ClearState(ftp_passive);
// cannot do passive. Do a little harmless rercursion here return _OpenDataConnection();
//
p_clearState(ftp_passive);
return p_openDataConnection();
} }
for(i=0;i<6;i++)
{ for (i = 0; i < 6; i++)
ucaddr[i] = (unsigned char) (paddr[i] & 0xff); ucaddr[i] = (unsigned char)(paddr[i] & 0xff);
}
memcpy(&sa.sin_addr, &ucaddr[0], (size_t) 4); memcpy(&sa.sin_addr, &ucaddr[0], (size_t) 4);
memcpy(&sa.sin_port, &ucaddr[4], (size_t) 2); memcpy(&sa.sin_port, &ucaddr[4], (size_t) 2);
addr.SetTo(sa); addr.SetTo(sa);
if(m_data->Connect(addr) == B_NO_ERROR) if (fData->Connect(addr) == B_NO_ERROR)
{
rc = true; rc = true;
}
} }
} }
} else { } else {
//
// cannot do passive. Do a little harmless rercursion here // cannot do passive. Do a little harmless rercursion here
// _ClearState(ftp_passive);
p_clearState(ftp_passive); rc = _OpenDataConnection();
rc = p_openDataConnection();
} }
} else { } else {
//
// Here we bind to a local port and send a PORT command // Here we bind to a local port and send a PORT command
// if (fData->Bind() == B_NO_ERROR) {
if(m_data->Bind() == B_NO_ERROR)
{
char buf[255]; char buf[255];
m_data->Listen(); fData->Listen();
addr = m_data->LocalAddr(); addr = fData->LocalAddr();
addr.GetAddr(buf, &port); addr.GetAddr(buf, &port);
host = buf; host = buf;
i=0; i = 0;
while(i >= 0) while (i >= 0) {
{
i = host.find('.', i); i = host.find('.', i);
if(i >= 0) if (i >= 0)
host[i] = ','; host[i] = ',';
} }
sprintf(buf, ",%d,%d", (port & 0xff00) >> 8, port & 0x00ff); sprintf(buf, ",%d,%d", (port & 0xff00) >> 8, port & 0x00ff);
cmd = "PORT "; cmd = "PORT ";
cmd += host; cmd += buf; cmd += host;
p_sendRequest(cmd); cmd += buf;
p_getReply(repstr, code, codetype); _SendRequest(cmd);
// _GetReply(replyString, code, codeType);
// PORT failure is in the 500-range // PORT failure is in the 500-range
// if (codeType == 2)
if(codetype == 2)
rc = true; rc = true;
} }
} }
@@ -707,32 +618,25 @@ bool FtpClient::p_openDataConnection()
} }
bool FtpClient::p_acceptDataConnection() bool
FtpClient::_AcceptDataConnection()
{ {
BNetEndpoint *ep; BNetEndpoint* endPoint;
bool rc = false; bool rc = false;
if(p_testState(ftp_passive) == false) if (_TestState(ftp_passive) == false) {
{ if (fData != 0) {
if(m_data != 0) endPoint = fData->Accept();
{ if (endPoint != 0) {
ep = m_data->Accept(); delete fData;
if(ep != 0) fData = endPoint;
{
delete m_data;
m_data = ep;
rc = true; rc = true;
} }
} }
} else { }
else
rc = true; rc = true;
}
return rc; return rc;
} }
+60 -48
View File
@@ -1,54 +1,15 @@
#include <string> #ifndef FTP_CLIENT_H
#include <File.h> #define FTP_CLIENT_H
#include <stdio.h> #include <stdio.h>
#include <string>
#include <File.h>
#include <NetworkKit.h> #include <NetworkKit.h>
using std::string; using std::string;
class FtpClient
{
public:
FtpClient();
~FtpClient();
enum ftp_mode
{
binary_mode,
ascii_mode
};
bool connect(const string &server, const string &login, const string &passwd);
bool putFile(const string &local, const string &remote, ftp_mode mode = binary_mode);
bool getFile(const string &remote, const string &local, ftp_mode mode = binary_mode);
bool moveFile(const string &oldpath, const string &newpath);
bool cd(const string &dir);
bool pwd(string &dir);
bool ls(string &listing);
void setPassive(bool on);
protected:
enum {
ftp_complete = 1UL,
ftp_connected = 2,
ftp_passive = 4
};
unsigned long m_state;
bool p_testState(unsigned long state);
void p_setState(unsigned long state);
void p_clearState(unsigned long state);
bool p_sendRequest(const string &cmd);
bool p_getReply(string &outstr, int &outcode, int &codetype);
bool p_getReplyLine(string &line);
bool p_openDataConnection();
bool p_acceptDataConnection();
BNetEndpoint *m_control;
BNetEndpoint *m_data;
};
/* /*
* Definitions for the TELNET protocol. Snarfed from the BSD source. * Definitions for the TELNET protocol. Snarfed from the BSD source.
@@ -58,5 +19,56 @@ protected:
#define DO 253 #define DO 253
#define WONT 252 #define WONT 252
#define WILL 251 #define WILL 251
#define xEOF 236 #define xEOF 236
class FtpClient {
public:
FtpClient();
~FtpClient();
enum ftp_mode {
binary_mode,
ascii_mode
};
bool Connect(const string& server, const string& login,
const string& passwd);
bool PutFile(const string& local, const string& remote,
ftp_mode mode = binary_mode);
bool GetFile(const string& remote, const string& local,
ftp_mode mode = binary_mode);
bool MoveFile(const string& oldPath, const string& newPath);
bool ChangeDir(const string& dir);
bool PrintWorkingDir(string& dir);
bool ListDirContents(string& listing);
void SetPassive(bool on);
protected:
enum {
ftp_complete = 1UL,
ftp_connected = 2,
ftp_passive = 4
};
bool _TestState(unsigned long state);
void _SetState(unsigned long state);
void _ClearState(unsigned long state);
bool _SendRequest(const string& cmd);
bool _GetReply(string& outString, int& outCode, int& codeType);
bool _GetReplyLine(string& line);
bool _OpenDataConnection();
bool _AcceptDataConnection();
unsigned long fState;
BNetEndpoint* fControl;
BNetEndpoint* fData;
};
#endif // FTP_CLIENT_H
+105 -78
View File
@@ -1,90 +1,101 @@
#include <Debug.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "Settings.h" #include "Settings.h"
Settings *settings = NULL; #include <stdio.h>
#include <stdlib.h>
#include <string.h>
// generic setting handler classes #include <Debug.h>
StringValueSetting::StringValueSetting(const char *name, const char *defaultValue, Settings* settings = NULL;
const char *valueExpectedErrorString, const char *wrongValueErrorString)
: SettingsArgvDispatcher(name),
defaultValue(defaultValue), StringValueSetting::StringValueSetting(const char* name, const char* defaultValue,
valueExpectedErrorString(valueExpectedErrorString), const char* valueExpectedErrorString, const char* wrongValueErrorString)
wrongValueErrorString(wrongValueErrorString), : SettingsArgvDispatcher(name),
value(strdup(defaultValue)) fDefaultValue(defaultValue),
fValueExpectedErrorString(valueExpectedErrorString),
fWrongValueErrorString(wrongValueErrorString),
fValue(strdup(defaultValue))
{ {
} }
StringValueSetting::~StringValueSetting() StringValueSetting::~StringValueSetting()
{ {
free(value); free(fValue);
} }
void void
StringValueSetting::ValueChanged(const char *newValue) StringValueSetting::ValueChanged(const char* newValue)
{ {
if (newValue == value) if (newValue == fValue)
// guard against self assingment // guard against self assingment
return; return;
free(value); free(fValue);
value = strdup(newValue); fValue = strdup(newValue);
} }
const char *
const char*
StringValueSetting::Value() const StringValueSetting::Value() const
{ {
return value; return fValue;
} }
void void
StringValueSetting::SaveSettingValue(Settings *settings) StringValueSetting::SaveSettingValue(Settings* settings)
{ {
printf("-------StringValueSetting::SaveSettingValue %s %s\n", Name(), value); printf("-------StringValueSetting::SaveSettingValue %s %s\n", Name(), fValue);
settings->Write("\"%s\"", value); settings->Write("\"%s\"", fValue);
} }
bool bool
StringValueSetting::NeedsSaving() const StringValueSetting::NeedsSaving() const
{ {
// needs saving if different than default // needs saving if different than default
return strcmp(value, defaultValue) != 0; return strcmp(fValue, fDefaultValue) != 0;
} }
const char *
const char*
StringValueSetting::Handle(const char *const *argv) StringValueSetting::Handle(const char *const *argv)
{ {
if (!*++argv) if (!*++argv)
return valueExpectedErrorString; return fValueExpectedErrorString;
ValueChanged(*argv); ValueChanged(*argv);
return 0; return 0;
} }
EnumeratedStringValueSetting::EnumeratedStringValueSetting(const char *name,
const char *defaultValue, const char *const *values, const char *valueExpectedErrorString, // #pragma mark -
const char *wrongValueErrorString)
: StringValueSetting(name, defaultValue, valueExpectedErrorString, wrongValueErrorString),
values(values) EnumeratedStringValueSetting::EnumeratedStringValueSetting(const char* name,
const char* defaultValue, const char *const *values,
const char* valueExpectedErrorString,
const char* wrongValueErrorString)
: StringValueSetting(name, defaultValue, valueExpectedErrorString, wrongValueErrorString),
fValues(values)
{ {
} }
void void
EnumeratedStringValueSetting::ValueChanged(const char *newValue) EnumeratedStringValueSetting::ValueChanged(const char* newValue)
{ {
#if DEBUG #if DEBUG
// must be one of the enumerated values // must be one of the enumerated values
bool found = false; bool found = false;
for (int32 index = 0; ; index++) { for (int32 index = 0; ; index++) {
if (!values[index]) if (!fValues[index])
break; break;
if (strcmp(values[index], newValue) != 0) if (strcmp(fValues[index], newValue) != 0)
continue; continue;
found = true; found = true;
break; break;
@@ -94,120 +105,136 @@ EnumeratedStringValueSetting::ValueChanged(const char *newValue)
StringValueSetting::ValueChanged(newValue); StringValueSetting::ValueChanged(newValue);
} }
const char *
const char*
EnumeratedStringValueSetting::Handle(const char *const *argv) EnumeratedStringValueSetting::Handle(const char *const *argv)
{ {
if (!*++argv) if (!*++argv)
return valueExpectedErrorString; return fValueExpectedErrorString;
printf("-----EnumeratedStringValueSetting::Handle %s %s\n", *(argv-1), *argv); printf("-----EnumeratedStringValueSetting::Handle %s %s\n", *(argv-1), *argv);
bool found = false; bool found = false;
for (int32 index = 0; ; index++) { for (int32 index = 0; ; index++) {
if (!values[index]) if (!fValues[index])
break; break;
if (strcmp(values[index], *argv) != 0) if (strcmp(fValues[index], *argv) != 0)
continue; continue;
found = true; found = true;
break; break;
} }
if (!found) if (!found)
return wrongValueErrorString; return fWrongValueErrorString;
ValueChanged(*argv); ValueChanged(*argv);
return 0; return 0;
} }
ScalarValueSetting::ScalarValueSetting(const char *name, int32 defaultValue,
const char *valueExpectedErrorString, const char *wrongValueErrorString, // #pragma mark -
ScalarValueSetting::ScalarValueSetting(const char* name, int32 defaultValue,
const char* valueExpectedErrorString, const char* wrongValueErrorString,
int32 min, int32 max) int32 min, int32 max)
: SettingsArgvDispatcher(name), : SettingsArgvDispatcher(name),
defaultValue(defaultValue), fDefaultValue(defaultValue),
value(defaultValue), fValue(defaultValue),
max(max), fMax(max),
min(min), fMin(min),
valueExpectedErrorString(valueExpectedErrorString), fValueExpectedErrorString(valueExpectedErrorString),
wrongValueErrorString(wrongValueErrorString) fWrongValueErrorString(wrongValueErrorString)
{ {
} }
void void
ScalarValueSetting::ValueChanged(int32 newValue) ScalarValueSetting::ValueChanged(int32 newValue)
{ {
ASSERT(newValue > min); ASSERT(newValue > fMin);
ASSERT(newValue < max); ASSERT(newValue < fMax);
value = newValue; fValue = newValue;
} }
int32 int32
ScalarValueSetting::Value() const ScalarValueSetting::Value() const
{ {
return value; return fValue;
} }
void void
ScalarValueSetting::GetValueAsString(char *buffer) const ScalarValueSetting::GetValueAsString(char* buffer) const
{ {
sprintf(buffer, "%ld", value); sprintf(buffer, "%ld", fValue);
} }
const char *
const char*
ScalarValueSetting::Handle(const char *const *argv) ScalarValueSetting::Handle(const char *const *argv)
{ {
if (!*++argv) if (!*++argv)
return valueExpectedErrorString; return fValueExpectedErrorString;
int32 newValue = atoi(*argv); int32 newValue = atoi(*argv);
if (newValue < min || newValue > max) if (newValue < fMin || newValue > fMax)
return wrongValueErrorString; return fWrongValueErrorString;
value = newValue; fValue = newValue;
return 0; return 0;
} }
void void
ScalarValueSetting::SaveSettingValue(Settings *settings) ScalarValueSetting::SaveSettingValue(Settings* settings)
{ {
settings->Write("%d", value); settings->Write("%d", fValue);
} }
bool bool
ScalarValueSetting::NeedsSaving() const ScalarValueSetting::NeedsSaving() const
{ {
return value != defaultValue; return fValue != fDefaultValue;
} }
BooleanValueSetting::BooleanValueSetting(const char *name, bool defaultValue ) // #pragma mark -
: ScalarValueSetting(name, defaultValue, 0, 0)
BooleanValueSetting::BooleanValueSetting(const char* name, bool defaultValue)
: ScalarValueSetting(name, defaultValue, 0, 0)
{ {
} }
bool bool
BooleanValueSetting::Value() const BooleanValueSetting::Value() const
{ {
return value; return fValue;
} }
const char *
const char*
BooleanValueSetting::Handle(const char *const *argv) BooleanValueSetting::Handle(const char *const *argv)
{ {
if (!*++argv) if (!*++argv)
return "or or off expected"; return "on or off expected";
if (strcmp(*argv, "on") == 0) if (strcmp(*argv, "on") == 0)
value = true; fValue = true;
else if (strcmp(*argv, "off") == 0) else if (strcmp(*argv, "off") == 0)
value = false; fValue = false;
else else
return "or or off expected"; return "on or off expected";
return 0; return 0;
} }
void
BooleanValueSetting::SaveSettingValue(Settings *settings)
{
settings->Write(value ? "on" : "off");
}
void
BooleanValueSetting::SaveSettingValue(Settings* settings)
{
settings->Write(fValue ? "on" : "off");
}
+43 -41
View File
@@ -1,84 +1,86 @@
#ifndef __SETTINGS__ #ifndef SETTINGS_H
#define __SETTINGS__ #define SETTINGS_H
#include "SettingsHandler.h" #include "SettingsHandler.h"
void SetUpSettings(char *filename); void SetUpSettings(char* filename);
void QuitSettings(); void QuitSettings();
class StringValueSetting : public SettingsArgvDispatcher { class StringValueSetting : public SettingsArgvDispatcher {
// simple string setting // simple string setting
public: public:
StringValueSetting(const char *name, const char *defaultValue, StringValueSetting(const char* name, const char* defaultValue,
const char *valueExpectedErrorString, const char* valueExpectedErrorString,
const char *wrongValueErrorString); const char* wrongValueErrorString);
virtual ~StringValueSetting(); virtual ~StringValueSetting();
void ValueChanged(const char *newValue); void ValueChanged(const char* newValue);
const char *Value() const; const char* Value() const;
virtual const char *Handle(const char *const *argv); virtual const char* Handle(const char *const *argv);
protected: protected:
virtual void SaveSettingValue(Settings *); virtual void SaveSettingValue(Settings*);
virtual bool NeedsSaving() const; virtual bool NeedsSaving() const;
const char *defaultValue; const char* fDefaultValue;
const char *valueExpectedErrorString; const char* fValueExpectedErrorString;
const char *wrongValueErrorString; const char* fWrongValueErrorString;
char *value; char* fValue;
}; };
class EnumeratedStringValueSetting : public StringValueSetting { class EnumeratedStringValueSetting : public StringValueSetting {
// string setting, values that do not match string enumeration // string setting, values that do not match string enumeration
// are rejected // are rejected
public: public:
EnumeratedStringValueSetting(const char *name, const char *defaultValue, EnumeratedStringValueSetting(const char* name, const char* defaultValue,
const char *const *values, const char *valueExpectedErrorString, const char *const *values, const char* valueExpectedErrorString,
const char *wrongValueErrorString); const char* wrongValueErrorString);
void ValueChanged(const char *newValue); void ValueChanged(const char* newValue);
virtual const char *Handle(const char *const *argv); virtual const char* Handle(const char *const *argv);
protected: protected:
const char *const *values; const char *const *fValues;
char *value; char* fValue;
}; };
class ScalarValueSetting : public SettingsArgvDispatcher { class ScalarValueSetting : public SettingsArgvDispatcher {
// simple int32 setting // simple int32 setting
public: public:
ScalarValueSetting(const char *name, int32 defaultValue, ScalarValueSetting(const char* name, int32 defaultValue,
const char *valueExpectedErrorString, const char *wrongValueErrorString, const char* valueExpectedErrorString, const char* wrongValueErrorString,
int32 min = LONG_MIN, int32 max = LONG_MAX); int32 min = LONG_MIN, int32 max = LONG_MAX);
void ValueChanged(int32 newValue); void ValueChanged(int32 newValue);
int32 Value() const; int32 Value() const;
void GetValueAsString(char *) const; void GetValueAsString(char*) const;
virtual const char *Handle(const char *const *argv); virtual const char* Handle(const char *const *argv);
protected: protected:
virtual void SaveSettingValue(Settings *); virtual void SaveSettingValue(Settings*);
virtual bool NeedsSaving() const; virtual bool NeedsSaving() const;
int32 defaultValue; int32 fDefaultValue;
int32 value; int32 fValue;
int32 max; int32 fMax;
int32 min; int32 fMin;
const char *valueExpectedErrorString; const char* fValueExpectedErrorString;
const char *wrongValueErrorString; const char* fWrongValueErrorString;
}; };
class BooleanValueSetting : public ScalarValueSetting { class BooleanValueSetting : public ScalarValueSetting {
// on-off setting // on-off setting
public: public:
BooleanValueSetting(const char *name, bool defaultValue); BooleanValueSetting(const char* name, bool defaultValue);
bool Value() const; bool Value() const;
virtual const char *Handle(const char *const *argv); virtual const char* Handle(const char *const *argv);
protected: protected:
virtual void SaveSettingValue(Settings *); virtual void SaveSettingValue(Settings *);
}; };
#endif #endif // SETTINGS_H
+203 -154
View File
@@ -1,73 +1,101 @@
#include <Directory.h>
#include <Entry.h>
#include <FindDirectory.h>
#include <File.h>
#include <Path.h>
#include <StopWatch.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <Debug.h>
#include "SettingsHandler.h" #include "SettingsHandler.h"
ArgvParser::ArgvParser(const char *name) #include <stdarg.h>
: file(0), #include <stdio.h>
buffer(0), #include <stdlib.h>
pos(-1), #include <string.h>
argc(0),
currentArgv(0), #include <Debug.h>
currentArgsPos(-1), #include <Directory.h>
sawBackslash(false), #include <Entry.h>
eatComment(false), #include <File.h>
inDoubleQuote(false), #include <FindDirectory.h>
inSingleQuote(false), #include <Path.h>
lineNo(0), #include <StopWatch.h>
fileName(name)
#if 0
static int
Compare(const SettingsArgvDispatcher* p1, const SettingsArgvDispatcher* p2)
{ {
file = fopen(fileName, "r"); return strcmp(p1->Name(), p2->Name());
if (!file) { }
PRINT(("Error opening %s\n", fileName)); #endif
#if 0
static int
CompareByNameOne(const SettingsArgvDispatcher* item1,
const SettingsArgvDispatcher* item2)
{
return strcmp(item1->Name(), item2->Name());
}
#endif
/*! \class ArgvParser
ArgvParser class opens a text file and passes the context in argv
format to a specified handler
*/
ArgvParser::ArgvParser(const char* name)
:
fFile(0),
fBuffer(0),
fPos(-1),
fArgc(0),
fCurrentArgv(0),
fCurrentArgsPos(-1),
fSawBackslash(false),
fEatComment(false),
fInDoubleQuote(false),
fInSingleQuote(false),
fLineNo(0),
fFileName(name)
{
fFile = fopen(fFileName, "r");
if (!fFile) {
PRINT(("Error opening %s\n", fFileName));
return; return;
} }
buffer = new char [kBufferSize]; fBuffer = new char [kBufferSize];
currentArgv = new char * [1024]; fCurrentArgv = new char* [1024];
} }
ArgvParser::~ArgvParser() ArgvParser::~ArgvParser()
{ {
delete [] buffer; delete[] fBuffer;
MakeArgvEmpty(); MakeArgvEmpty();
delete [] currentArgv; delete [] fCurrentArgv;
if (file) if (fFile)
fclose(file); fclose(fFile);
} }
void void
ArgvParser::MakeArgvEmpty() ArgvParser::MakeArgvEmpty()
{ {
// done with current argv, free it up // done with current argv, free it up
for (int32 index = 0; index < argc; index++) for (int32 index = 0; index < fArgc; index++)
delete currentArgv[index]; delete fCurrentArgv[index];
argc = 0; fArgc = 0;
} }
status_t status_t
ArgvParser::SendArgv(ArgvHandler argvHandlerFunc, void *passThru) ArgvParser::SendArgv(ArgvHandler argvHandlerFunc, void* passThru)
{ {
if (argc) { if (fArgc) {
NextArgv(); NextArgv();
currentArgv[argc] = 0; fCurrentArgv[fArgc] = 0;
const char *result = (argvHandlerFunc)(argc, currentArgv, passThru); const char *result = (argvHandlerFunc)(fArgc, fCurrentArgv, passThru);
if (result) if (result)
printf("File %s; Line %ld # %s", fileName, lineNo, result); printf("File %s; Line %ld # %s", fFileName, fLineNo, result);
MakeArgvEmpty(); MakeArgvEmpty();
if (result) if (result)
return B_ERROR; return B_ERROR;
@@ -76,54 +104,60 @@ ArgvParser::SendArgv(ArgvHandler argvHandlerFunc, void *passThru)
return B_NO_ERROR; return B_NO_ERROR;
} }
void void
ArgvParser::NextArgv() ArgvParser::NextArgv()
{ {
if (sawBackslash) { if (fSawBackslash) {
currentArgs[++currentArgsPos] = '\\'; fCurrentArgs[++fCurrentArgsPos] = '\\';
sawBackslash = false; fSawBackslash = false;
} }
currentArgs[++currentArgsPos] = '\0'; fCurrentArgs[++fCurrentArgsPos] = '\0';
// terminate current arg pos // terminate current arg pos
// copy it as a string to the current argv slot // copy it as a string to the current argv slot
currentArgv[argc] = new char [strlen(currentArgs) + 1]; fCurrentArgv[fArgc] = new char [strlen(fCurrentArgs) + 1];
strcpy(currentArgv[argc], currentArgs); strcpy(fCurrentArgv[fArgc], fCurrentArgs);
currentArgsPos = -1; fCurrentArgsPos = -1;
argc++; fArgc++;
} }
void void
ArgvParser::NextArgvIfNotEmpty() ArgvParser::NextArgvIfNotEmpty()
{ {
if (!sawBackslash && currentArgsPos < 0) if (!fSawBackslash && fCurrentArgsPos < 0)
return; return;
NextArgv(); NextArgv();
} }
char char
ArgvParser::GetCh() ArgvParser::GetCh()
{ {
if (pos < 0 || buffer[pos] == 0) { if (fPos < 0 || fBuffer[fPos] == 0) {
if (file == 0) if (fFile == 0)
return EOF; return EOF;
if (fgets(buffer, kBufferSize, file) == 0) if (fgets(fBuffer, kBufferSize, fFile) == 0)
return EOF; return EOF;
pos = 0; fPos = 0;
} }
return buffer[pos++]; return fBuffer[fPos++];
} }
status_t status_t
ArgvParser::EachArgv(const char *name, ArgvHandler argvHandlerFunc, void *passThru) ArgvParser::EachArgv(const char* name, ArgvHandler argvHandlerFunc, void* passThru)
{ {
ArgvParser parser(name); ArgvParser parser(name);
return parser.EachArgvPrivate(name, argvHandlerFunc, passThru); return parser.EachArgvPrivate(name, argvHandlerFunc, passThru);
} }
status_t status_t
ArgvParser::EachArgvPrivate(const char *name, ArgvHandler argvHandlerFunc, void *passThru) ArgvParser::EachArgvPrivate(const char* name, ArgvHandler argvHandlerFunc,
void* passThru)
{ {
status_t result; status_t result;
@@ -131,7 +165,7 @@ ArgvParser::EachArgvPrivate(const char *name, ArgvHandler argvHandlerFunc, void
char ch = GetCh(); char ch = GetCh();
if (ch == EOF) { if (ch == EOF) {
// done with file // done with file
if (inDoubleQuote || inSingleQuote) { if (fInDoubleQuote || fInSingleQuote) {
printf("File %s # unterminated quote at end of file\n", name); printf("File %s # unterminated quote at end of file\n", name);
result = B_ERROR; result = B_ERROR;
break; break;
@@ -142,15 +176,15 @@ ArgvParser::EachArgvPrivate(const char *name, ArgvHandler argvHandlerFunc, void
if (ch == '\n' || ch == '\r') { if (ch == '\n' || ch == '\r') {
// handle new line // handle new line
eatComment = false; fEatComment = false;
if (!sawBackslash && (inDoubleQuote || inSingleQuote)) { if (!fSawBackslash && (fInDoubleQuote || fInSingleQuote)) {
printf("File %s ; Line %ld # unterminated quote\n", name, lineNo); printf("File %s ; Line %ld # unterminated quote\n", name, fLineNo);
result = B_ERROR; result = B_ERROR;
break; break;
} }
lineNo++; fLineNo++;
if (sawBackslash) { if (fSawBackslash) {
sawBackslash = false; fSawBackslash = false;
continue; continue;
} }
// end of line, flush all argv // end of line, flush all argv
@@ -160,11 +194,11 @@ ArgvParser::EachArgvPrivate(const char *name, ArgvHandler argvHandlerFunc, void
continue; continue;
} }
if (eatComment) if (fEatComment)
continue; continue;
if (!sawBackslash) { if (!fSawBackslash) {
if (!inDoubleQuote && !inSingleQuote) { if (!fInDoubleQuote && !fInSingleQuote) {
if (ch == ';') { if (ch == ';') {
// semicolon is a command separator, pass on the whole argv // semicolon is a command separator, pass on the whole argv
result = SendArgv(argvHandlerFunc, passThru); result = SendArgv(argvHandlerFunc, passThru);
@@ -173,47 +207,52 @@ ArgvParser::EachArgvPrivate(const char *name, ArgvHandler argvHandlerFunc, void
continue; continue;
} else if (ch == '#') { } else if (ch == '#') {
// ignore everything on this line after this character // ignore everything on this line after this character
eatComment = true; fEatComment = true;
continue; continue;
} else if (ch == ' ' || ch == '\t') { } else if (ch == ' ' || ch == '\t') {
// space or tab separates the individual arg strings // space or tab separates the individual arg strings
NextArgvIfNotEmpty(); NextArgvIfNotEmpty();
continue; continue;
} else if (!sawBackslash && ch == '\\') { } else if (!fSawBackslash && ch == '\\') {
// the next character is escaped // the next character is escaped
sawBackslash = true; fSawBackslash = true;
continue; continue;
} }
} }
if (!inSingleQuote && ch == '"') { if (!fInSingleQuote && ch == '"') {
// enter/exit double quote handling // enter/exit double quote handling
inDoubleQuote = !inDoubleQuote; fInDoubleQuote = !fInDoubleQuote;
continue; continue;
} }
if (!inDoubleQuote && ch == '\'') { if (!fInDoubleQuote && ch == '\'') {
// enter/exit single quote handling // enter/exit single quote handling
inSingleQuote = !inSingleQuote; fInSingleQuote = !fInSingleQuote;
continue; continue;
} }
} else { } else {
// we just pass through the escape sequence as is // we just pass through the escape sequence as is
currentArgs[++currentArgsPos] = '\\'; fCurrentArgs[++fCurrentArgsPos] = '\\';
sawBackslash = false; fSawBackslash = false;
} }
currentArgs[++currentArgsPos] = ch; fCurrentArgs[++fCurrentArgsPos] = ch;
} }
return result; return result;
} }
SettingsArgvDispatcher::SettingsArgvDispatcher(const char *name) // #pragma mark -
: name(name)
SettingsArgvDispatcher::SettingsArgvDispatcher(const char* name)
:
fName(name)
{ {
} }
void void
SettingsArgvDispatcher::SaveSettings(Settings *settings, bool onlyIfNonDefault) SettingsArgvDispatcher::SaveSettings(Settings* settings, bool onlyIfNonDefault)
{ {
if (!onlyIfNonDefault || NeedsSaving()) { if (!onlyIfNonDefault || NeedsSaving()) {
settings->Write("%s ", Name()); settings->Write("%s ", Name());
@@ -222,8 +261,9 @@ SettingsArgvDispatcher::SaveSettings(Settings *settings, bool onlyIfNonDefault)
} }
} }
bool bool
SettingsArgvDispatcher::HandleRectValue(BRect &result, const char *const *argv, SettingsArgvDispatcher::HandleRectValue(BRect &result, const char* const *argv,
bool printError) bool printError)
{ {
if (!*argv) { if (!*argv) {
@@ -253,158 +293,165 @@ SettingsArgvDispatcher::HandleRectValue(BRect &result, const char *const *argv,
return true; return true;
} }
void void
SettingsArgvDispatcher::WriteRectValue(Settings *setting, BRect rect) SettingsArgvDispatcher::WriteRectValue(Settings* setting, BRect rect)
{ {
setting->Write("%d %d %d %d", (int32)rect.left, (int32)rect.top, setting->Write("%d %d %d %d", (int32)rect.left, (int32)rect.top,
(int32)rect.right, (int32)rect.bottom); (int32)rect.right, (int32)rect.bottom);
} }
#if 0
static int
CompareByNameOne(const SettingsArgvDispatcher *item1, const SettingsArgvDispatcher *item2)
{
return strcmp(item1->Name(), item2->Name());
}
#endif
Settings::Settings(const char *filename, const char *settingsDirName) // #pragma mark -
: fileName(filename),
settingsDir(settingsDirName),
list(0), /*! \class Settings
count(0), this class represents a list of all the settings handlers, reads and
listSize(30), saves the settings file
currentSettings(0) */
Settings::Settings(const char* filename, const char* settingsDirName)
:
fFileName(filename),
fSettingsDir(settingsDirName),
fList(0),
fCount(0),
fListSize(30),
fCurrentSettings(0)
{ {
#ifdef SINGLE_SETTING_FILE #ifdef SINGLE_SETTING_FILE
settingsHandler = this; settingsHandler = this;
#endif #endif
list = (SettingsArgvDispatcher **)calloc(listSize, sizeof(SettingsArgvDispatcher *)); fList = (SettingsArgvDispatcher**)calloc(fListSize, sizeof(SettingsArgvDispatcher *));
} }
Settings::~Settings() Settings::~Settings()
{ {
for (int32 index = 0; index < count; index++) for (int32 index = 0; index < fCount; index++)
delete list[index]; delete fList[index];
free(list); free(fList);
} }
const char * const char*
Settings::ParseUserSettings(int, const char *const *argv, void *castToThis) Settings::_ParseUserSettings(int, const char* const *argv, void* castToThis)
{ {
if (!*argv) if (!*argv)
return 0; return 0;
#ifdef SINGLE_SETTING_FILE #ifdef SINGLE_SETTING_FILE
Settings *settings = settingsHandler; Settings* settings = settingsHandler;
#else #else
Settings *settings = (Settings *)castToThis; Settings* settings = (Settings*)castToThis;
#endif #endif
SettingsArgvDispatcher *handler = settings->Find(*argv); SettingsArgvDispatcher* handler = settings->_Find(*argv);
if (!handler) if (!handler)
return "unknown command"; return "unknown command";
return handler->Handle(argv); return handler->Handle(argv);
} }
#if 0 /*!
static int Returns false if argv dispatcher with the same name already
Compare(const SettingsArgvDispatcher *p1, const SettingsArgvDispatcher *p2) registered
{ */
return strcmp(p1->Name(), p2->Name()); bool
} Settings::Add(SettingsArgvDispatcher* setting)
#endif
bool
Settings::Add(SettingsArgvDispatcher *setting)
{ {
// check for uniqueness // check for uniqueness
if (Find(setting->Name())) if (_Find(setting->Name()))
return false; return false;
if (count >= listSize) { if (fCount >= fListSize) {
listSize += 30; fListSize += 30;
list = (SettingsArgvDispatcher **)realloc(list, fList = (SettingsArgvDispatcher **)realloc(fList,
listSize * sizeof(SettingsArgvDispatcher *)); fListSize * sizeof(SettingsArgvDispatcher *));
} }
list[count++] = setting; fList[fCount++] = setting;
return true; return true;
} }
SettingsArgvDispatcher *
Settings::Find(const char *name) SettingsArgvDispatcher*
Settings::_Find(const char* name)
{ {
for (int32 index = 0; index < count; index++) for (int32 index = 0; index < fCount; index++)
if (strcmp(name, list[index]->Name()) == 0) if (strcmp(name, fList[index]->Name()) == 0)
return list[index]; return fList[index];
return 0; return 0;
} }
void
void
Settings::TryReadingSettings() Settings::TryReadingSettings()
{ {
BPath prefsPath; BPath prefsPath;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefsPath, true) == B_OK) { if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefsPath, true) == B_OK) {
prefsPath.Append(settingsDir); prefsPath.Append(fSettingsDir);
BPath path(prefsPath); BPath path(prefsPath);
path.Append(fileName); path.Append(fFileName);
ArgvParser::EachArgv(path.Path(), Settings::ParseUserSettings, this); ArgvParser::EachArgv(path.Path(), Settings::_ParseUserSettings, this);
} }
} }
void void
Settings::SaveSettings(bool onlyIfNonDefault) Settings::SaveSettings(bool onlyIfNonDefault)
{ {
ASSERT(SettingsHandler()); ASSERT(SettingsHandler());
SettingsHandler()->SaveCurrentSettings(onlyIfNonDefault); SettingsHandler()->_SaveCurrentSettings(onlyIfNonDefault);
} }
void void
Settings::MakeSettingsDirectory(BDirectory *resultingSettingsDir) Settings::_MakeSettingsDirectory(BDirectory *resultingSettingsDir)
{ {
BPath path; BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) != B_OK) if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) != B_OK)
return; return;
// make sure there is a directory // make sure there is a directory
path.Append(settingsDir); path.Append(fSettingsDir);
mkdir(path.Path(), 0777); mkdir(path.Path(), 0777);
resultingSettingsDir->SetTo(path.Path()); resultingSettingsDir->SetTo(path.Path());
} }
void
Settings::SaveCurrentSettings(bool onlyIfNonDefault)
{
BDirectory settingsDir;
MakeSettingsDirectory(&settingsDir);
if (settingsDir.InitCheck() != B_OK) void
Settings::_SaveCurrentSettings(bool onlyIfNonDefault)
{
BDirectory fSettingsDir;
_MakeSettingsDirectory(&fSettingsDir);
if (fSettingsDir.InitCheck() != B_OK)
return; return;
printf("+++++++++++ Settings::SaveCurrentSettings %s\n", fileName);
printf("+++++++++++ Settings::_SaveCurrentSettings %s\n", fFileName);
// nuke old settings // nuke old settings
BEntry entry(&settingsDir, fileName); BEntry entry(&fSettingsDir, fFileName);
entry.Remove(); entry.Remove();
BFile prefs(&entry, O_RDWR | O_CREAT); BFile prefs(&entry, O_RDWR | O_CREAT);
if (prefs.InitCheck() != B_OK) if (prefs.InitCheck() != B_OK)
return; return;
currentSettings = &prefs; fCurrentSettings = &prefs;
for (int32 index = 0; index < count; index++) { for (int32 index = 0; index < fCount; index++) {
list[index]->SaveSettings(this, onlyIfNonDefault); fList[index]->SaveSettings(this, onlyIfNonDefault);
} }
currentSettings = 0; fCurrentSettings = 0;
} }
void void
Settings::Write(const char *format, ...) Settings::Write(const char* format, ...)
{ {
va_list args; va_list args;
@@ -413,15 +460,17 @@ Settings::Write(const char *format, ...)
va_end(args); va_end(args);
} }
void void
Settings::VSWrite(const char *format, va_list arg) Settings::VSWrite(const char* format, va_list arg)
{ {
char buffer[2048]; char buffer[2048];
vsprintf(buffer, format, arg); vsprintf(buffer, format, arg);
ASSERT(currentSettings && currentSettings->InitCheck() == B_OK); ASSERT(fCurrentSettings && fCurrentSettings->InitCheck() == B_OK);
currentSettings->Write(buffer, strlen(buffer)); fCurrentSettings->Write(buffer, strlen(buffer));
} }
#ifdef SINGLE_SETTING_FILE #ifdef SINGLE_SETTING_FILE
Settings *Settings::settingsHandler = 0; Settings* Settings::settingsHandler = 0;
#endif #endif
+103 -97
View File
@@ -1,11 +1,14 @@
#ifndef __SETTINGS_FILE__ #ifndef SETTINGS_HANDLER_H
#define __SETTINGS_FILE__ #define SETTINGS_HANDLER_H
#include <SupportDefs.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include <SupportDefs.h>
class BFile; class BFile;
class BDirectory; class BDirectory;
@@ -13,136 +16,139 @@ class BRect;
class Settings; class Settings;
typedef const char *(*ArgvHandler)(int argc, const char *const *argv, void *params); typedef const char* (*ArgvHandler)(int argc, const char *const *argv, void *params);
// return 0 or error string if parsing failed // return 0 or error string if parsing failed
const int32 kBufferSize = 1024; const int32 kBufferSize = 1024;
class ArgvParser { class ArgvParser {
// this class opens a text file and passes the context in argv public:
// format to a specified handler static status_t EachArgv(const char* name,
public: ArgvHandler argvHandlerFunc, void* passThru);
static status_t EachArgv(const char *name,
ArgvHandler argvHandlerFunc, void *passThru);
private: private:
ArgvParser(const char *name); ArgvParser(const char* name);
~ArgvParser(); ~ArgvParser();
status_t EachArgvPrivate(const char *name, status_t EachArgvPrivate(const char* name,
ArgvHandler argvHandlerFunc, void *passThru); ArgvHandler argvHandlerFunc, void* passThru);
char GetCh(); char GetCh();
status_t SendArgv(ArgvHandler argvHandlerFunc, void *passThru);
// done with a whole line of argv, send it off and get ready
// to build a new one
void NextArgv(); status_t SendArgv(ArgvHandler argvHandlerFunc, void* passThru);
// done with current string, get ready to start building next // done with a whole line of argv, send it off and get ready
void NextArgvIfNotEmpty(); // to build a new one
// as above, don't commint current string if empty
void MakeArgvEmpty(); void NextArgv();
// done with current string, get ready to start building next
void NextArgvIfNotEmpty();
// as above, don't commint current string if empty
FILE *file; void MakeArgvEmpty();
char *buffer;
int32 pos;
int32 numAvail;
int argc;
char **currentArgv;
int32 currentArgsPos; FILE* fFile;
char currentArgs [1024]; char* fBuffer;
int32 fPos;
int32 fNumAvail;
bool sawBackslash; int fArgc;
bool eatComment; char** fCurrentArgv;
bool inDoubleQuote;
bool inSingleQuote;
int32 lineNo; int32 fCurrentArgsPos;
const char *fileName; char fCurrentArgs[1024];
bool fSawBackslash;
bool fEatComment;
bool fInDoubleQuote;
bool fInSingleQuote;
int32 fLineNo;
const char* fFileName;
}; };
class SettingsArgvDispatcher { class SettingsArgvDispatcher {
// base class for a single setting item // base class for a single setting item
public: public:
SettingsArgvDispatcher(const char *name); SettingsArgvDispatcher(const char* name);
void SaveSettings(Settings *settings, bool onlyIfNonDefault); void SaveSettings(Settings* settings, bool onlyIfNonDefault);
const char *Name() const const char* Name() const
{ return name; } {
// name as it appears in the settings file return fName;
}
virtual const char *Handle(const char *const *argv) = 0;
// override this adding an argv parser that reads in the
// values in argv format for this setting
// return a pointer to an error message or null if parsed OK
virtual const char* Handle(const char* const *argv) = 0;
// override this adding an argv parser that reads in the
// values in argv format for this setting
// return a pointer to an error message or null if parsed OK
// some handy reader/writer calls bool HandleRectValue(BRect&, const char* const *argv,
bool HandleRectValue(BRect &, const char *const *argv, bool printError = true); bool printError = true);
// static bool HandleColorValue(rgb_color &, const char *const *argv, bool printError = true);
void WriteRectValue(Settings *, BRect);
// void WriteColorValue(BRect);
protected: // static bool HandleColorValue(rgb_color &, const char *const *argv, bool printError = true);
virtual void SaveSettingValue(Settings *settings) = 0; void WriteRectValue(Settings*, BRect);
// override this to save the current value of this setting in a // void WriteColorValue(BRect);
// text format
protected:
virtual bool NeedsSaving() const virtual void SaveSettingValue(Settings* settings) = 0;
{ return true; } // override this to save the current value of this setting in a
// text format
virtual bool NeedsSaving() const
{
return true;
}
// override to return false if current value is equal to the default // override to return false if current value is equal to the default
// and does not need saving // and does not need saving
private: private:
const char *name; const char* fName;
}; };
class Settings { class Settings {
// this class is a list of all the settings handlers, reads and public:
// saves the settings file Settings(const char* filename, const char* settingsDirName);
public: ~Settings();
Settings(const char *filename, const char *settingsDirName); void TryReadingSettings();
~Settings(); void SaveSettings(bool onlyIfNonDefault = true);
void TryReadingSettings();
void SaveSettings(bool onlyIfNonDefault = true);
#ifdef SINGLE_SETTING_FILE #ifdef SINGLE_SETTING_FILE
static Settings *SettingsHandler() static Settings* SettingsHandler()
{ return settingsHandler; } {
return settingsHandler;
}
#else #else
Settings *SettingsHandler() Settings* SettingsHandler()
{ return this; } {
return this;
}
#endif #endif
bool Add(SettingsArgvDispatcher *); bool Add(SettingsArgvDispatcher *);
// return false if argv dispatcher with the same name already
// registered
void Write(const char *format, ...); void Write(const char* format, ...);
void VSWrite(const char *, va_list); void VSWrite(const char*, va_list);
#ifdef SINGLE_SETTING_FILE #ifdef SINGLE_SETTING_FILE
static Settings *settingsHandler; static Settings* settingsHandler;
#endif #endif
private: private:
void MakeSettingsDirectory(BDirectory *); void _MakeSettingsDirectory(BDirectory*);
SettingsArgvDispatcher *Find(const char *); SettingsArgvDispatcher* _Find(const char*);
static const char *ParseUserSettings(int, const char *const *argv, void *); static const char* _ParseUserSettings(int, const char *const *argv, void*);
void SaveCurrentSettings(bool onlyIfNonDefault); void _SaveCurrentSettings(bool onlyIfNonDefault);
const char *fileName; const char* fFileName;
const char *settingsDir; const char* fSettingsDir;
SettingsArgvDispatcher **list; SettingsArgvDispatcher** fList;
int32 count; int32 fCount;
int32 listSize; int32 fListSize;
BFile *currentSettings; BFile* fCurrentSettings;
}; };
#endif // SETTINGS_HANDLER_H
#endif
File diff suppressed because it is too large Load Diff
+123 -151
View File
@@ -1,176 +1,148 @@
// Copyright (c) 1998-99, Be Incorporated, All Rights Reserved. // Copyright (c) 1998-99, Be Incorporated, All Rights Reserved.
// SMS // SMS
/* VideoConsumer.h */ /* VideoConsumer.h */
#ifndef VIDEO_CONSUMER_H
#define VIDEO_CONSUMER_H
#if !defined(VID_CONSUMER_H)
#define VID_CONSUMER_H
#include <View.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Window.h>
#include <MediaNode.h>
#include <TranslationKit.h>
#include <BufferConsumer.h> #include <BufferConsumer.h>
#include <TimedEventQueue.h>
#include <MediaEventLooper.h> #include <MediaEventLooper.h>
#include <MediaNode.h>
#include <TimedEventQueue.h>
#include <TranslationKit.h>
#include <View.h>
#include <Window.h>
typedef struct
{ typedef struct {
port_id port; port_id port;
bigtime_t rate; bigtime_t rate;
uint32 imageFormat; uint32 imageFormat;
int32 translator; int32 translator;
bool passiveFtp; bool passiveFtp;
char fileNameText[64]; char fileNameText[64];
char serverText[64]; char serverText[64];
char loginText[64]; char loginText[64];
char passwordText[64]; char passwordText[64];
char directoryText[64]; char directoryText[64];
} ftp_msg_info; } ftp_msg_info;
#define FTP_INFO 0x60000001 #define FTP_INFO 0x60000001
class VideoConsumer : class BStringView;
public BMediaEventLooper,
public BBufferConsumer
{
public:
VideoConsumer(
const char * name,
BView * view,
BStringView * statusLine,
BMediaAddOn *addon,
const uint32 internal_id);
~VideoConsumer();
/* BMediaNode */
public:
virtual BMediaAddOn *AddOn(long *cookie) const;
protected:
virtual void Start(bigtime_t performance_time);
virtual void Stop(bigtime_t performance_time, bool immediate);
virtual void Seek(bigtime_t media_time, bigtime_t performance_time);
virtual void TimeWarp(bigtime_t at_real_time, bigtime_t to_performance_time);
virtual void NodeRegistered();
virtual status_t RequestCompleted( class VideoConsumer : public BMediaEventLooper, public BBufferConsumer {
const media_request_info & info); public:
VideoConsumer(const char* name, BView* view, BStringView* statusLine,
BMediaAddOn *addon, const uint32 internalId);
~VideoConsumer();
/* BMediaNode */
public:
virtual BMediaAddOn* AddOn(long* cookie) const;
protected:
virtual void Start(bigtime_t performanceTime);
virtual void Stop(bigtime_t performanceTime, bool immediate);
virtual void Seek(bigtime_t mediaTime, bigtime_t performanceTime);
virtual void TimeWarp(bigtime_t atRealTime,
bigtime_t toPerformanceTime);
virtual void NodeRegistered();
virtual status_t RequestCompleted(const media_request_info& info);
virtual status_t HandleMessage(int32 message, const void* data,
size_t size);
virtual status_t DeleteHook(BMediaNode* node);
/* BMediaEventLooper */
protected:
virtual void HandleEvent(const media_timed_event* event,
bigtime_t lateness, bool realTimeEvent);
/* BBufferConsumer */
public:
virtual status_t AcceptFormat(const media_destination& dest,
media_format* format);
virtual status_t GetNextInput(int32* cookie, media_input* outInput);
virtual void DisposeInputCookie(int32 cookie);
protected:
virtual void BufferReceived(BBuffer* buffer);
private:
virtual void ProducerDataStatus(const media_destination &forWhom,
int32 status, bigtime_t atMediaTime);
virtual status_t GetLatencyFor(const media_destination& forWhom,
bigtime_t* outLatency, media_node_id* outId);
virtual status_t Connected(const media_source& producer,
const media_destination& where, const media_format& withFormat,
media_input* outInput);
virtual void Disconnected(const media_source& producer,
const media_destination& where);
virtual status_t FormatChanged(const media_source& producer,
const media_destination& consumer, int32 fromChangeCount,
const media_format& format);
/* implementation */
public:
status_t CreateBuffers(const media_format& withFormat);
void DeleteBuffers();
static status_t FtpRun(void* data);
void FtpThread();
virtual status_t HandleMessage( void UpdateFtpStatus(char* status);
int32 message,
const void * data,
size_t size);
virtual status_t DeleteHook(BMediaNode * node); status_t LocalSave(char* filename, BBitmap* bitmap);
/* BMediaEventLooper */ status_t FtpSave(char* filename);
protected:
virtual void HandleEvent(
const media_timed_event *event,
bigtime_t lateness,
bool realTimeEvent);
/* BBufferConsumer */
public:
virtual status_t AcceptFormat(
const media_destination &dest,
media_format * format);
virtual status_t GetNextInput(
int32 * cookie,
media_input * out_input);
virtual void DisposeInputCookie(
int32 cookie);
protected:
virtual void BufferReceived( private:
BBuffer * buffer); BStringView* fStatusLine;
uint32 fInternalID;
private: BMediaAddOn* fAddOn;
virtual void ProducerDataStatus( thread_id fFtpThread;
const media_destination &for_whom,
int32 status,
bigtime_t at_media_time);
virtual status_t GetLatencyFor(
const media_destination &for_whom,
bigtime_t * out_latency,
media_node_id * out_id);
virtual status_t Connected(
const media_source &producer,
const media_destination &where,
const media_format & with_format,
media_input * out_input);
virtual void Disconnected(
const media_source &producer,
const media_destination &where);
virtual status_t FormatChanged(
const media_source & producer,
const media_destination & consumer,
int32 from_change_count,
const media_format & format);
/* implementation */
public: bool fConnectionActive;
status_t CreateBuffers( media_input fIn;
const media_format & with_format); media_destination fDestination;
bigtime_t fMyLatency;
void DeleteBuffers();
static status_t FtpRun(
void *data);
void FtpThread(
void);
void UpdateFtpStatus(
char *status);
status_t LocalSave(
char *filename,
BBitmap *bitmap);
status_t FtpSave( BWindow* fWindow;
char *filename); BView* fView;
BBitmap* fBitmap[3];
bool fOurBuffers;
BBufferGroup* fBuffers;
uint32 fBufferMap[3];
private: BBitmap* fFtpBitmap;
volatile bool fTimeToFtp;
volatile bool fFtpComplete;
BStringView * mStatusLine; bigtime_t fRate;
uint32 mInternalID; uint32 fImageFormat;
BMediaAddOn *mAddOn; int32 fTranslator;
bool fPassiveFtp;
thread_id mFtpThread; char fFileNameText[64];
char fServerText[64];
bool mConnectionActive; char fLoginText[64];
media_input mIn; char fPasswordText[64];
media_destination mDestination; char fDirectoryText[64];
bigtime_t mMyLatency;
BWindow *mWindow;
BView *mView;
BBitmap *mBitmap[3];
bool mOurBuffers;
BBufferGroup *mBuffers;
uint32 mBufferMap[3];
BBitmap *mFtpBitmap;
volatile bool mTimeToFtp;
volatile bool mFtpComplete;
bigtime_t mRate;
uint32 mImageFormat;
int32 mTranslator;
bool mPassiveFtp;
char mFileNameText[64];
char mServerText[64];
char mLoginText[64];
char mPasswordText[64];
char mDirectoryText[64];
}; };
#endif #endif // VIDEO_CONSUMER_H