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
+254 -241
View File
@@ -1,23 +1,24 @@
#include "CodyCam.h" #include "CodyCam.h"
#include <Alert.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <Alert.h>
#include <Button.h> #include <Button.h>
#include <TabView.h>
#include <Menu.h>
#include <MenuItem.h>
#include <MenuBar.h>
#include <PopUpMenu.h>
#include <MediaDefs.h> #include <MediaDefs.h>
#include <MediaNode.h> #include <MediaNode.h>
#include <scheduler.h>
#include <MediaTheme.h>
#include <TimeSource.h>
#include <MediaRoster.h> #include <MediaRoster.h>
#include <MediaTheme.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <scheduler.h>
#include <TabView.h>
#include <TextControl.h> #include <TextControl.h>
#include <TimeSource.h>
#include <TranslationKit.h> #include <TranslationKit.h>
#include <unistd.h>
#define VIDEO_SIZE_X 320 #define VIDEO_SIZE_X 320
@@ -38,40 +39,93 @@ const int32 kMenuHeight = 15;
const int32 kButtonHeight = 15; const int32 kButtonHeight = 15;
const int32 kSliderViewRectHeight = 40; const int32 kSliderViewRectHeight = 40;
const rgb_color kViewGray = { 216, 216, 216, 255}; const rgb_color kViewGray = {216, 216, 216, 255};
static void ErrorAlert(const char * message, status_t err); static void ErrorAlert(const char* message, status_t err);
static status_t AddTranslationItems( BMenu * intoMenu, uint32 from_type); static status_t AddTranslationItems(BMenu* intoMenu, uint32 fromType);
#define CALL printf #define CALL printf
#define ERROR printf #define ERROR printf
#define FTPINFO printf #define FTPINFO printf
#define INFO printf #define INFO printf
//---------------------------------------------------------------
// The Application
//---------------------------------------------------------------
int main() { // Utility functions
chdir("/boot/home");
CodyCam app; static void
app.Run(); ErrorAlert(const char* message, status_t err)
return 0; {
(new BAlert("", message, "Quit"))->Go();
printf("%s\n%s [%lx]", message, strerror(err), err);
be_app->PostMessage(B_QUIT_REQUESTED);
} }
//---------------------------------------------------------------
CodyCam::CodyCam() : status_t
BApplication("application/x-vnd.Be.CodyCam"), AddTranslationItems(BMenu* intoMenu, uint32 fromType)
{
BTranslatorRoster* use;
char* translatorTypeName;
const char* translatorIdName;
use = BTranslatorRoster::Default();
translatorIdName = "be:translator";
translatorTypeName = "be:type";
translator_id* ids = NULL;
int32 count = 0;
status_t err = use->GetAllTranslators(&ids, &count);
if (err < B_OK)
return err;
for (int tix = 0; tix < count; tix++) {
const translation_format* formats = NULL;
int32 num_formats = 0;
bool ok = false;
err = use->GetInputFormats(ids[tix], &formats, &num_formats);
if (err == B_OK)
for (int iix = 0; iix < num_formats; iix++) {
if (formats[iix].type == fromType) {
ok = true;
break;
}
}
if (!ok)
continue;
err = use->GetOutputFormats(ids[tix], &formats, &num_formats);
if (err == B_OK)
for (int oix = 0; oix < num_formats; oix++) {
if (formats[oix].type != fromType) {
BMessage* itemmsg;
itemmsg = new BMessage(msg_translate);
itemmsg->AddInt32(translatorIdName, ids[tix]);
itemmsg->AddInt32(translatorTypeName, formats[oix].type);
intoMenu->AddItem(new BMenuItem(formats[oix].name, itemmsg));
}
}
}
delete[] ids;
return B_OK;
}
// #pragma mark -
CodyCam::CodyCam()
: BApplication("application/x-vnd.Be.CodyCam"),
fMediaRoster(NULL), fMediaRoster(NULL),
fVideoConsumer(NULL), fVideoConsumer(NULL),
fWindow(NULL), fWindow(NULL),
fPort(0), fPort(0),
mVideoControlWindow(NULL) fVideoControlWindow(NULL)
{ {
} }
//---------------------------------------------------------------
CodyCam::~CodyCam() CodyCam::~CodyCam()
{ {
@@ -87,50 +141,47 @@ CodyCam::~CodyCam()
CALL("CodyCam::~CodyCam - EXIT\n"); CALL("CodyCam::~CodyCam - EXIT\n");
} }
//---------------------------------------------------------------
void void
CodyCam::ReadyToRun() CodyCam::ReadyToRun()
{ {
/* create the window for the app */ /* create the window for the app */
fWindow = new VideoWindow(BRect(28, 28, 28 + (WINDOW_SIZE_X-1), 28 + (WINDOW_SIZE_Y-1)), fWindow = new VideoWindow(BRect(28, 28, 28 + (WINDOW_SIZE_X - 1),
(const char *)"CodyCam", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE, &fPort); 28 + (WINDOW_SIZE_Y - 1)), (const char*)"CodyCam", B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE, &fPort);
/* set up the node connections */ /* set up the node connections */
status_t status = SetUpNodes(); status_t status = _SetUpNodes();
if (status != B_OK) if (status != B_OK) {
{ // This error is not needed because _SetUpNodes handles displaying any
// This error is not needed because SetUpNodes handles displaying any
// errors it runs into. // errors it runs into.
// ErrorAlert("Error setting up nodes", status); // ErrorAlert("Error setting up nodes", status);
return; return;
} }
((VideoWindow *)fWindow)->ApplyControls(); ((VideoWindow*)fWindow)->ApplyControls();
} }
//---------------------------------------------------------------
bool bool
CodyCam::QuitRequested() CodyCam::QuitRequested()
{ {
TearDownNodes(); _TearDownNodes();
snooze(100000); snooze(100000);
return true; return true;
} }
//---------------------------------------------------------------
void void
CodyCam::MessageReceived(BMessage *message) CodyCam::MessageReceived(BMessage *message)
{ {
switch (message->what) switch (message->what) {
{
case msg_start: case msg_start:
{ {
BTimeSource *timeSource = fMediaRoster->MakeTimeSourceFor(fTimeSourceNode); BTimeSource* timeSource = fMediaRoster->MakeTimeSourceFor(fTimeSourceNode);
bigtime_t real = BTimeSource::RealTime(); bigtime_t real = BTimeSource::RealTime();
bigtime_t perf = timeSource->PerformanceTimeFor(real) + 10000; bigtime_t perf = timeSource->PerformanceTimeFor(real) + 10000;
status_t status = fMediaRoster->StartNode(fProducerNode, perf); status_t status = fMediaRoster->StartNode(fProducerNode, perf);
@@ -139,57 +190,54 @@ CodyCam::MessageReceived(BMessage *message)
timeSource->Release(); timeSource->Release();
break; break;
} }
case msg_stop: case msg_stop:
fMediaRoster->StopNode(fProducerNode, 0, true); fMediaRoster->StopNode(fProducerNode, 0, true);
break; break;
case msg_video: case msg_video:
{ {
if (mVideoControlWindow) { if (fVideoControlWindow) {
mVideoControlWindow->Activate(); fVideoControlWindow->Activate();
break; break;
} }
BParameterWeb * web = NULL; BParameterWeb* web = NULL;
BView * view = NULL; BView* view = NULL;
media_node node = fProducerNode; media_node node = fProducerNode;
status_t err = fMediaRoster->GetParameterWebFor(node, &web); status_t err = fMediaRoster->GetParameterWebFor(node, &web);
if ((err >= B_OK) && if (err >= B_OK && web != NULL) {
(web != NULL))
{
view = BMediaTheme::ViewFor(web); view = BMediaTheme::ViewFor(web);
mVideoControlWindow = new ControlWindow( fVideoControlWindow = new ControlWindow(
BRect(2*WINDOW_OFFSET_X + WINDOW_SIZE_X, WINDOW_OFFSET_Y, BRect(2 * WINDOW_OFFSET_X + WINDOW_SIZE_X, WINDOW_OFFSET_Y,
2*WINDOW_OFFSET_X + WINDOW_SIZE_X + view->Bounds().right, WINDOW_OFFSET_Y + view->Bounds().bottom), 2 * WINDOW_OFFSET_X + WINDOW_SIZE_X + view->Bounds().right,
view, node); WINDOW_OFFSET_Y + view->Bounds().bottom), view, node);
fMediaRoster->StartWatching(BMessenger(NULL, mVideoControlWindow), node, B_MEDIA_WEB_CHANGED); fMediaRoster->StartWatching(BMessenger(NULL, fVideoControlWindow), node,
mVideoControlWindow->Show(); B_MEDIA_WEB_CHANGED);
fVideoControlWindow->Show();
} }
break; break;
} }
case msg_about: case msg_about:
{ (new BAlert("About CodyCam", "CodyCam\n\nThe Original BeOS WebCam",
(new BAlert("About CodyCam", "CodyCam\n\nThe Original BeOS WebCam", "Close"))->Go(); "Close"))->Go();
break; break;
}
case msg_control_win: case msg_control_win:
{
// our control window is being asked to go away // our control window is being asked to go away
// set our pointer to NULL // set our pointer to NULL
mVideoControlWindow = NULL; fVideoControlWindow = NULL;
break; break;
}
default: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(message);
break; break;
} }
} }
//---------------------------------------------------------------
status_t status_t
CodyCam::SetUpNodes() CodyCam::_SetUpNodes()
{ {
status_t status = B_OK; status_t status = B_OK;
@@ -199,12 +247,14 @@ CodyCam::SetUpNodes()
ErrorAlert("Can't find the media roster", status); ErrorAlert("Can't find the media roster", status);
return status; return status;
} }
/* find the time source */ /* find the time source */
status = fMediaRoster->GetTimeSource(&fTimeSourceNode); status = fMediaRoster->GetTimeSource(&fTimeSourceNode);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert("Can't get a time source", status); ErrorAlert("Can't get a time source", status);
return status; return status;
} }
/* find a video producer node */ /* find a video producer node */
INFO("CodyCam acquiring VideoInput node\n"); INFO("CodyCam acquiring VideoInput node\n");
status = fMediaRoster->GetVideoInput(&fProducerNode); status = fMediaRoster->GetVideoInput(&fProducerNode);
@@ -214,7 +264,8 @@ CodyCam::SetUpNodes()
} }
/* create the video consumer node */ /* create the video consumer node */
fVideoConsumer = new VideoConsumer("CodyCam", ((VideoWindow *)fWindow)->VideoView(), ((VideoWindow *)fWindow)->StatusLine(), NULL, 0); fVideoConsumer = new VideoConsumer("CodyCam", ((VideoWindow*)fWindow)->VideoView(),
((VideoWindow*)fWindow)->StatusLine(), NULL, 0);
if (!fVideoConsumer) { if (!fVideoConsumer) {
ErrorAlert("Can't create a video window", B_ERROR); ErrorAlert("Can't create a video window", B_ERROR);
return B_ERROR; return B_ERROR;
@@ -230,7 +281,8 @@ CodyCam::SetUpNodes()
/* find free producer output */ /* find free producer output */
int32 cnt = 0; int32 cnt = 0;
status = fMediaRoster->GetFreeOutputsFor(fProducerNode, &fProducerOut, 1, &cnt, B_MEDIA_RAW_VIDEO); status = fMediaRoster->GetFreeOutputsFor(fProducerNode, &fProducerOut, 1, &cnt,
B_MEDIA_RAW_VIDEO);
if (status != B_OK || cnt < 1) { if (status != B_OK || cnt < 1) {
status = B_RESOURCE_UNAVAILABLE; status = B_RESOURCE_UNAVAILABLE;
ErrorAlert("Can't find an available video stream", status); ErrorAlert("Can't find an available video stream", status);
@@ -239,7 +291,8 @@ CodyCam::SetUpNodes()
/* find free consumer input */ /* find free consumer input */
cnt = 0; cnt = 0;
status = fMediaRoster->GetFreeInputsFor(fVideoConsumer->Node(), &fConsumerIn, 1, &cnt, B_MEDIA_RAW_VIDEO); status = fMediaRoster->GetFreeInputsFor(fVideoConsumer->Node(), &fConsumerIn, 1,
&cnt, B_MEDIA_RAW_VIDEO);
if (status != B_OK || cnt < 1) { if (status != B_OK || cnt < 1) {
status = B_RESOURCE_UNAVAILABLE; status = B_RESOURCE_UNAVAILABLE;
ErrorAlert("Can't find an available connection to the video window", status); ErrorAlert("Can't find an available connection to the video window", status);
@@ -249,8 +302,8 @@ CodyCam::SetUpNodes()
/* Connect The Nodes!!! */ /* Connect The Nodes!!! */
media_format format; media_format format;
format.type = B_MEDIA_RAW_VIDEO; format.type = B_MEDIA_RAW_VIDEO;
media_raw_video_format vid_format = media_raw_video_format vid_format = {0, 1, 0, 239, B_VIDEO_TOP_LEFT_RIGHT,
{ 0, 1, 0, 239, B_VIDEO_TOP_LEFT_RIGHT, 1, 1, {B_RGB32, VIDEO_SIZE_X, VIDEO_SIZE_Y, VIDEO_SIZE_X*4, 0, 0}}; 1, 1, {B_RGB32, VIDEO_SIZE_X, VIDEO_SIZE_Y, VIDEO_SIZE_X * 4, 0, 0}};
format.u.raw_video = vid_format; format.u.raw_video = vid_format;
/* connect producer to consumer */ /* connect producer to consumer */
@@ -261,7 +314,9 @@ CodyCam::SetUpNodes()
return status; return status;
} }
/* set time sources */ /* set time sources */
status = fMediaRoster->SetTimeSourceFor(fProducerNode.node, fTimeSourceNode.node); status = fMediaRoster->SetTimeSourceFor(fProducerNode.node, fTimeSourceNode.node);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert("Can't set the timesource for the video source", status); ErrorAlert("Can't set the timesource for the video source", status);
@@ -284,17 +339,18 @@ CodyCam::SetUpNodes()
status = fMediaRoster->GetInitialLatencyFor(fProducerNode, &initLatency); status = fMediaRoster->GetInitialLatencyFor(fProducerNode, &initLatency);
if (status < B_OK) { if (status < B_OK) {
ErrorAlert("error getting initial latency for fCaptureNode", status); ErrorAlert("error getting initial latency for fCaptureNode", status);
return status;
} }
initLatency += estimate_max_scheduling_latency(); initLatency += estimate_max_scheduling_latency();
BTimeSource *timeSource = fMediaRoster->MakeTimeSourceFor(fProducerNode); BTimeSource* timeSource = fMediaRoster->MakeTimeSourceFor(fProducerNode);
bool running = timeSource->IsRunning(); bool running = timeSource->IsRunning();
/* workaround for people without sound cards */ /* workaround for people without sound cards */
/* because the system time source won't be running */ /* because the system time source won't be running */
bigtime_t real = BTimeSource::RealTime(); bigtime_t real = BTimeSource::RealTime();
if (!running) if (!running) {
{
status = fMediaRoster->StartTimeSource(fTimeSourceNode, real); status = fMediaRoster->StartTimeSource(fTimeSourceNode, real);
if (status != B_OK) { if (status != B_OK) {
timeSource->Release(); timeSource->Release();
@@ -327,17 +383,15 @@ CodyCam::SetUpNodes()
return status; return status;
} }
//---------------------------------------------------------------
void void
CodyCam::TearDownNodes() CodyCam::_TearDownNodes()
{ {
CALL("CodyCam::TearDownNodes\n"); CALL("CodyCam::_TearDownNodes\n");
if (!fMediaRoster) if (!fMediaRoster)
return; return;
if (fVideoConsumer) if (fVideoConsumer) {
{
/* stop */ /* stop */
INFO("stopping nodes!\n"); INFO("stopping nodes!\n");
// fMediaRoster->StopNode(fProducerNode, 0, true); // fMediaRoster->StopNode(fProducerNode, 0, true);
@@ -345,7 +399,7 @@ CodyCam::TearDownNodes()
/* disconnect */ /* disconnect */
fMediaRoster->Disconnect(fProducerOut.node.node, fProducerOut.source, fMediaRoster->Disconnect(fProducerOut.node.node, fProducerOut.source,
fConsumerIn.node.node, fConsumerIn.destination); fConsumerIn.node.node, fConsumerIn.destination);
if (fProducerNode != media_node::null) { if (fProducerNode != media_node::null) {
INFO("CodyCam releasing fProducerNode\n"); INFO("CodyCam releasing fProducerNode\n");
@@ -357,71 +411,14 @@ CodyCam::TearDownNodes()
} }
} }
//---------------------------------------------------------------
// Utility functions
//---------------------------------------------------------------
static void // #pragma mark - Video Window Class
ErrorAlert(const char * message, status_t err)
{
(new BAlert("", message, "Quit"))->Go();
printf("%s\n%s [%lx]", message, strerror(err), err);
be_app->PostMessage(B_QUIT_REQUESTED);
}
//--------------------------------------------------------------- VideoWindow::VideoWindow (BRect frame, const char* title, window_type type, uint32 flags,
port_id* consumerPort)
status_t : BWindow(frame,title,type,flags),
AddTranslationItems( BMenu * intoMenu, uint32 from_type) fPortPtr(consumerPort),
{
BTranslatorRoster * use;
char * translator_type_name;
const char * translator_id_name;
use = BTranslatorRoster::Default();
translator_id_name = "be:translator";
translator_type_name = "be:type";
translator_id * ids = NULL;
int32 count = 0;
status_t err = use->GetAllTranslators(&ids, &count);
if (err < B_OK) return err;
for (int tix=0; tix<count; tix++) {
const translation_format * formats = NULL;
int32 num_formats = 0;
bool ok = false;
err = use->GetInputFormats(ids[tix], &formats, &num_formats);
if (err == B_OK) for (int iix=0; iix<num_formats; iix++) {
if (formats[iix].type == from_type) {
ok = true;
break;
}
}
if (!ok) continue;
err = use->GetOutputFormats(ids[tix], &formats, &num_formats);
if (err == B_OK) for (int oix=0; oix<num_formats; oix++) {
if (formats[oix].type != from_type) {
BMessage * itemmsg;
itemmsg = new BMessage(msg_translate);
itemmsg->AddInt32(translator_id_name, ids[tix]);
itemmsg->AddInt32(translator_type_name, formats[oix].type);
intoMenu->AddItem(new BMenuItem(formats[oix].name, itemmsg));
}
}
}
delete[] ids;
return B_OK;
}
//---------------------------------------------------------------
// Video Window Class
//---------------------------------------------------------------
VideoWindow::VideoWindow (BRect frame, const char *title, window_type type, uint32 flags, port_id * consumerport) :
BWindow(frame,title,type,flags),
fPortPtr(consumerport),
fView(NULL), fView(NULL),
fVideoView(NULL) fVideoView(NULL)
{ {
@@ -436,9 +433,9 @@ VideoWindow::VideoWindow (BRect frame, const char *title, window_type type, uint
strcpy(fFtpInfo.passwordText, "password"); strcpy(fFtpInfo.passwordText, "password");
strcpy(fFtpInfo.directoryText, "directory"); strcpy(fFtpInfo.directoryText, "directory");
SetUpSettings("codycam", ""); _SetUpSettings("codycam", "");
BMenuBar* menuBar = new BMenuBar(BRect(0,0,0,0), "menu bar"); BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), "menu bar");
AddChild(menuBar); AddChild(menuBar);
BMenuItem* menuItem; BMenuItem* menuItem;
@@ -482,11 +479,11 @@ VideoWindow::VideoWindow (BRect frame, const char *title, window_type type, uint
AddChild(fView); AddChild(fView);
/* add some controls */ /* add some controls */
BuildCaptureControls(fView); _BuildCaptureControls(fView);
/* add another view to hold the video image */ /* add another view to hold the video image */
aRect = BRect(0, 0, VIDEO_SIZE_X - 1, VIDEO_SIZE_Y - 1); aRect = BRect(0, 0, VIDEO_SIZE_X - 1, VIDEO_SIZE_Y - 1);
aRect.OffsetBy((WINDOW_SIZE_X - VIDEO_SIZE_X)/2, kYBuffer); aRect.OffsetBy((WINDOW_SIZE_X - VIDEO_SIZE_X) / 2, kYBuffer);
fVideoView = new BView(aRect, "Video View", B_FOLLOW_ALL, B_WILL_DRAW); fVideoView = new BView(aRect, "Video View", B_FOLLOW_ALL, B_WILL_DRAW);
fView->AddChild(fVideoView); fView->AddChild(fVideoView);
@@ -494,14 +491,14 @@ VideoWindow::VideoWindow (BRect frame, const char *title, window_type type, uint
Show(); Show();
} }
//---------------------------------------------------------------
VideoWindow::~VideoWindow() VideoWindow::~VideoWindow()
{ {
QuitSettings(); _QuitSettings();
} }
//---------------------------------------------------------------
bool bool
VideoWindow::QuitRequested() VideoWindow::QuitRequested()
@@ -510,171 +507,180 @@ VideoWindow::QuitRequested()
return false; return false;
} }
//---------------------------------------------------------------
void void
VideoWindow::MessageReceived(BMessage *message) VideoWindow::MessageReceived(BMessage* message)
{ {
BControl *p; BControl* control;
p = NULL; control = NULL;
message->FindPointer((const char *)"source",(void **)&p); message->FindPointer((const char*)"source", (void **)&control);
switch (message->what) switch (message->what) {
{
case msg_filename: case msg_filename:
if (p != NULL) if (control != NULL) {
{ strncpy(fFtpInfo.fileNameText, ((BTextControl*)control)->Text(), 63);
strncpy(fFtpInfo.fileNameText, ((BTextControl *)p)->Text(), 63);
FTPINFO("file is '%s'\n", fFtpInfo.fileNameText); FTPINFO("file is '%s'\n", fFtpInfo.fileNameText);
} }
break; break;
case msg_rate_15s: case msg_rate_15s:
FTPINFO("fifteen seconds\n"); FTPINFO("fifteen seconds\n");
fFtpInfo.rate = (bigtime_t)(15 * 1000000); fFtpInfo.rate = (bigtime_t)(15 * 1000000);
break; break;
case msg_rate_30s: case msg_rate_30s:
FTPINFO("thirty seconds\n"); FTPINFO("thirty seconds\n");
fFtpInfo.rate = (bigtime_t)(30 * 1000000); fFtpInfo.rate = (bigtime_t)(30 * 1000000);
break; break;
case msg_rate_1m: case msg_rate_1m:
FTPINFO("one minute\n"); FTPINFO("one minute\n");
fFtpInfo.rate = (bigtime_t)(1 * 60 * 1000000); fFtpInfo.rate = (bigtime_t)(1 * 60 * 1000000);
break; break;
case msg_rate_5m: case msg_rate_5m:
FTPINFO("five minute\n"); FTPINFO("five minute\n");
fFtpInfo.rate = (bigtime_t)(5 * 60 * 1000000); fFtpInfo.rate = (bigtime_t)(5 * 60 * 1000000);
break; break;
case msg_rate_10m: case msg_rate_10m:
FTPINFO("ten minute\n"); FTPINFO("ten minute\n");
fFtpInfo.rate = (bigtime_t)(10 * 60 * 1000000); fFtpInfo.rate = (bigtime_t)(10 * 60 * 1000000);
break; break;
case msg_rate_15m: case msg_rate_15m:
FTPINFO("fifteen minute\n"); FTPINFO("fifteen minute\n");
fFtpInfo.rate = (bigtime_t)(15 * 60 * 1000000); fFtpInfo.rate = (bigtime_t)(15 * 60 * 1000000);
break; break;
case msg_rate_30m: case msg_rate_30m:
FTPINFO("thirty minute\n"); FTPINFO("thirty minute\n");
fFtpInfo.rate = (bigtime_t)(30 * 60 * 1000000); fFtpInfo.rate = (bigtime_t)(30 * 60 * 1000000);
break; break;
case msg_rate_1h: case msg_rate_1h:
FTPINFO("one hour\n"); FTPINFO("one hour\n");
fFtpInfo.rate = (bigtime_t)(60LL * 60LL * 1000000LL); fFtpInfo.rate = (bigtime_t)(60LL * 60LL * 1000000LL);
break; break;
case msg_rate_2h: case msg_rate_2h:
FTPINFO("two hour\n"); FTPINFO("two hour\n");
fFtpInfo.rate = (bigtime_t)(2LL * 60LL * 60LL * 1000000LL); fFtpInfo.rate = (bigtime_t)(2LL * 60LL * 60LL * 1000000LL);
break; break;
case msg_rate_4h: case msg_rate_4h:
FTPINFO("four hour\n"); FTPINFO("four hour\n");
fFtpInfo.rate = (bigtime_t)(4LL * 60LL * 60LL * 1000000LL); fFtpInfo.rate = (bigtime_t)(4LL * 60LL * 60LL * 1000000LL);
break; break;
case msg_rate_8h: case msg_rate_8h:
FTPINFO("eight hour\n"); FTPINFO("eight hour\n");
fFtpInfo.rate = (bigtime_t)(8LL * 60LL * 60LL * 1000000LL); fFtpInfo.rate = (bigtime_t)(8LL * 60LL * 60LL * 1000000LL);
break; break;
case msg_rate_24h: case msg_rate_24h:
FTPINFO("24 hour\n"); FTPINFO("24 hour\n");
fFtpInfo.rate = (bigtime_t)(24LL * 60LL * 60LL * 1000000LL); fFtpInfo.rate = (bigtime_t)(24LL * 60LL * 60LL * 1000000LL);
break; break;
case msg_rate_never: case msg_rate_never:
FTPINFO("never\n"); FTPINFO("never\n");
fFtpInfo.rate = (bigtime_t)(B_INFINITE_TIMEOUT); fFtpInfo.rate = (bigtime_t)(B_INFINITE_TIMEOUT);
break; break;
case msg_translate: case msg_translate:
message->FindInt32("be:type", (int32 *)&(fFtpInfo.imageFormat)); message->FindInt32("be:type", (int32*)&(fFtpInfo.imageFormat));
message->FindInt32("be:translator", &(fFtpInfo.translator)); message->FindInt32("be:translator", &(fFtpInfo.translator));
break; break;
case msg_server: case msg_server:
if (p != NULL) if (control != NULL) {
{ strncpy(fFtpInfo.serverText, ((BTextControl*)control)->Text(), 64);
strncpy(fFtpInfo.serverText, ((BTextControl *)p)->Text(), 64);
FTPINFO("server = '%s'\n", fFtpInfo.serverText); FTPINFO("server = '%s'\n", fFtpInfo.serverText);
} }
break; break;
case msg_login: case msg_login:
if (p != NULL) if (control != NULL) {
{ strncpy(fFtpInfo.loginText, ((BTextControl*)control)->Text(), 64);
strncpy(fFtpInfo.loginText, ((BTextControl *)p)->Text(), 64);
FTPINFO("login = '%s'\n", fFtpInfo.loginText); FTPINFO("login = '%s'\n", fFtpInfo.loginText);
} }
break; break;
case msg_password: case msg_password:
if (p != NULL) if (control != NULL) {
{ strncpy(fFtpInfo.passwordText, ((BTextControl*)control)->Text(), 64);
strncpy(fFtpInfo.passwordText, ((BTextControl *)p)->Text(), 64);
FTPINFO("password = '%s'\n", fFtpInfo.passwordText); FTPINFO("password = '%s'\n", fFtpInfo.passwordText);
if (Lock()) if (Lock()) {
{ ((BTextControl*)control)->SetText("<HIDDEN>");
((BTextControl *)p)->SetText("<HIDDEN>");
Unlock(); Unlock();
} }
} }
break; break;
case msg_directory: case msg_directory:
if (p != NULL) if (control != NULL) {
{ strncpy(fFtpInfo.directoryText, ((BTextControl*)control)->Text(), 64);
strncpy(fFtpInfo.directoryText, ((BTextControl *)p)->Text(), 64);
FTPINFO("directory = '%s'\n", fFtpInfo.directoryText); FTPINFO("directory = '%s'\n", fFtpInfo.directoryText);
} }
break; break;
case msg_passiveftp: case msg_passiveftp:
if (p != NULL) if (control != NULL) {
{ fFtpInfo.passiveFtp = ((BCheckBox*)control)->Value();
fFtpInfo.passiveFtp = ((BCheckBox *)p)->Value();
if (fFtpInfo.passiveFtp) if (fFtpInfo.passiveFtp)
FTPINFO("using passive ftp\n"); FTPINFO("using passive ftp\n");
} }
break; break;
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
return; return;
} }
if (*fPortPtr) if (*fPortPtr)
write_port(*fPortPtr, FTP_INFO, (void *)&fFtpInfo, sizeof(ftp_msg_info)); write_port(*fPortPtr, FTP_INFO, (void*)&fFtpInfo, sizeof(ftp_msg_info));
} }
//---------------------------------------------------------------
BView * BView*
VideoWindow::VideoView() VideoWindow::VideoView()
{ {
return fVideoView; return fVideoView;
} }
//---------------------------------------------------------------
BStringView * BStringView*
VideoWindow::StatusLine() VideoWindow::StatusLine()
{ {
return fStatusLine; return fStatusLine;
} }
//---------------------------------------------------------------
void void
VideoWindow::BuildCaptureControls(BView *theView) VideoWindow::_BuildCaptureControls(BView* theView)
{ {
BRect aFrame, theFrame; BRect aFrame, theFrame;
theFrame = theView->Bounds(); theFrame = theView->Bounds();
theFrame.top += VIDEO_SIZE_Y + 2*kYBuffer + 40; theFrame.top += VIDEO_SIZE_Y + 2 * kYBuffer + 40;
theFrame.left += kXBuffer; theFrame.left += kXBuffer;
theFrame.right -= (WINDOW_SIZE_X/2 + 5); theFrame.right -= (WINDOW_SIZE_X / 2 + 5);
theFrame.bottom -= kXBuffer; theFrame.bottom -= kXBuffer;
fCaptureSetupBox = new BBox( theFrame, "Capture Controls", B_FOLLOW_ALL, B_WILL_DRAW); fCaptureSetupBox = new BBox(theFrame, "Capture Controls", B_FOLLOW_ALL, B_WILL_DRAW);
fCaptureSetupBox->SetLabel("Capture Controls"); fCaptureSetupBox->SetLabel("Capture Controls");
theView->AddChild(fCaptureSetupBox); theView->AddChild(fCaptureSetupBox);
aFrame = fCaptureSetupBox->Bounds(); aFrame = fCaptureSetupBox->Bounds();
aFrame.InsetBy(kXBuffer,kYBuffer); aFrame.InsetBy(kXBuffer, kYBuffer);
aFrame.top += kYBuffer/2; aFrame.top += kYBuffer / 2;
aFrame.bottom = aFrame.top + kMenuHeight; aFrame.bottom = aFrame.top + kMenuHeight;
fFileName = new BTextControl(aFrame, "File Name", "File Name:", fFilenameSetting->Value(), new BMessage(msg_filename)); fFileName = new BTextControl(aFrame, "File Name", "File Name:",
fFilenameSetting->Value(), new BMessage(msg_filename));
fFileName->SetTarget(BMessenger(NULL, this)); fFileName->SetTarget(BMessenger(NULL, this));
fFileName->SetDivider(fFileName->Divider() - 30); fFileName->SetDivider(fFileName->Divider() - 30);
@@ -686,10 +692,12 @@ VideoWindow::BuildCaptureControls(BView *theView)
fImageFormatMenu = new BPopUpMenu("Image Format Menu"); fImageFormatMenu = new BPopUpMenu("Image Format Menu");
AddTranslationItems(fImageFormatMenu, B_TRANSLATOR_BITMAP); AddTranslationItems(fImageFormatMenu, B_TRANSLATOR_BITMAP);
fImageFormatMenu->SetTargetForItems(this); fImageFormatMenu->SetTargetForItems(this);
if (fImageFormatMenu->FindItem("JPEG Image") != NULL) if (fImageFormatMenu->FindItem("JPEG Image") != NULL)
fImageFormatMenu->FindItem("JPEG Image")->SetMarked(true); fImageFormatMenu->FindItem("JPEG Image")->SetMarked(true);
else else
fImageFormatMenu->ItemAt(0)->SetMarked(true); fImageFormatMenu->ItemAt(0)->SetMarked(true);
fImageFormatSelector = new BMenuField(aFrame, "Format", "Format:", fImageFormatMenu); fImageFormatSelector = new BMenuField(aFrame, "Format", "Format:", fImageFormatMenu);
fImageFormatSelector->SetDivider(fImageFormatSelector->Divider() - 30); fImageFormatSelector->SetDivider(fImageFormatSelector->Divider() - 30);
fCaptureSetupBox->AddChild(fImageFormatSelector); fCaptureSetupBox->AddChild(fImageFormatSelector);
@@ -698,19 +706,19 @@ VideoWindow::BuildCaptureControls(BView *theView)
aFrame.bottom = aFrame.top + kMenuHeight; aFrame.bottom = aFrame.top + kMenuHeight;
fCaptureRateMenu = new BPopUpMenu("Capture Rate Menu"); fCaptureRateMenu = new BPopUpMenu("Capture Rate Menu");
fCaptureRateMenu->AddItem(new BMenuItem("Every 15 seconds",new BMessage(msg_rate_15s))); fCaptureRateMenu->AddItem(new BMenuItem("Every 15 seconds", new BMessage(msg_rate_15s)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 30 seconds",new BMessage(msg_rate_30s))); fCaptureRateMenu->AddItem(new BMenuItem("Every 30 seconds", new BMessage(msg_rate_30s)));
fCaptureRateMenu->AddItem(new BMenuItem("Every minute",new BMessage(msg_rate_1m))); fCaptureRateMenu->AddItem(new BMenuItem("Every minute", new BMessage(msg_rate_1m)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 5 minutes",new BMessage(msg_rate_5m))); fCaptureRateMenu->AddItem(new BMenuItem("Every 5 minutes", new BMessage(msg_rate_5m)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 10 minutes",new BMessage(msg_rate_10m))); fCaptureRateMenu->AddItem(new BMenuItem("Every 10 minutes", new BMessage(msg_rate_10m)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 15 minutes",new BMessage(msg_rate_15m))); fCaptureRateMenu->AddItem(new BMenuItem("Every 15 minutes", new BMessage(msg_rate_15m)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 30 minutes",new BMessage(msg_rate_30m))); fCaptureRateMenu->AddItem(new BMenuItem("Every 30 minutes", new BMessage(msg_rate_30m)));
fCaptureRateMenu->AddItem(new BMenuItem("Every hour",new BMessage(msg_rate_1h))); fCaptureRateMenu->AddItem(new BMenuItem("Every hour", new BMessage(msg_rate_1h)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 2 hours",new BMessage(msg_rate_2h))); fCaptureRateMenu->AddItem(new BMenuItem("Every 2 hours", new BMessage(msg_rate_2h)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 4 hours",new BMessage(msg_rate_4h))); fCaptureRateMenu->AddItem(new BMenuItem("Every 4 hours", new BMessage(msg_rate_4h)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 8 hours",new BMessage(msg_rate_8h))); fCaptureRateMenu->AddItem(new BMenuItem("Every 8 hours", new BMessage(msg_rate_8h)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 24 hours",new BMessage(msg_rate_24h))); fCaptureRateMenu->AddItem(new BMenuItem("Every 24 hours", new BMessage(msg_rate_24h)));
fCaptureRateMenu->AddItem(new BMenuItem("Never",new BMessage(msg_rate_never))); fCaptureRateMenu->AddItem(new BMenuItem("Never", new BMessage(msg_rate_never)));
fCaptureRateMenu->SetTargetForItems(this); fCaptureRateMenu->SetTargetForItems(this);
fCaptureRateMenu->FindItem(fCaptureRateSetting->Value())->SetMarked(true); fCaptureRateMenu->FindItem(fCaptureRateSetting->Value())->SetMarked(true);
fCaptureRateSelector = new BMenuField(aFrame, "Rate", "Rate:", fCaptureRateMenu); fCaptureRateSelector = new BMenuField(aFrame, "Rate", "Rate:", fCaptureRateMenu);
@@ -718,12 +726,12 @@ VideoWindow::BuildCaptureControls(BView *theView)
fCaptureSetupBox->AddChild(fCaptureRateSelector); fCaptureSetupBox->AddChild(fCaptureRateSelector);
aFrame = theView->Bounds(); aFrame = theView->Bounds();
aFrame.top += VIDEO_SIZE_Y + 2*kYBuffer + 40; aFrame.top += VIDEO_SIZE_Y + 2 * kYBuffer + 40;
aFrame.left += WINDOW_SIZE_X/2 + 5; aFrame.left += WINDOW_SIZE_X / 2 + 5;
aFrame.right -= kXBuffer; aFrame.right -= kXBuffer;
aFrame.bottom -= kYBuffer; aFrame.bottom -= kYBuffer;
fFtpSetupBox = new BBox( aFrame, "Ftp Setup", B_FOLLOW_ALL, B_WILL_DRAW); fFtpSetupBox = new BBox(aFrame, "Ftp Setup", B_FOLLOW_ALL, B_WILL_DRAW);
fFtpSetupBox->SetLabel("Ftp Setup"); fFtpSetupBox->SetLabel("Ftp Setup");
theView->AddChild(fFtpSetupBox); theView->AddChild(fFtpSetupBox);
@@ -733,7 +741,8 @@ VideoWindow::BuildCaptureControls(BView *theView)
aFrame.bottom = aFrame.top + kMenuHeight; aFrame.bottom = aFrame.top + kMenuHeight;
aFrame.right = aFrame.left + 160; aFrame.right = aFrame.left + 160;
fServerName = new BTextControl(aFrame, "Server", "Server:", fServerSetting->Value(), new BMessage(msg_server)); fServerName = new BTextControl(aFrame, "Server", "Server:", fServerSetting->Value(),
new BMessage(msg_server));
fServerName->SetTarget(this); fServerName->SetTarget(this);
fServerName->SetDivider(fServerName->Divider() - 30); fServerName->SetDivider(fServerName->Divider() - 30);
fFtpSetupBox->AddChild(fServerName); fFtpSetupBox->AddChild(fServerName);
@@ -741,7 +750,8 @@ VideoWindow::BuildCaptureControls(BView *theView)
aFrame.top = aFrame.bottom + kYBuffer; aFrame.top = aFrame.bottom + kYBuffer;
aFrame.bottom = aFrame.top + kMenuHeight; aFrame.bottom = aFrame.top + kMenuHeight;
fLoginId = new BTextControl(aFrame, "Login", "Login:", fLoginSetting->Value(), new BMessage(msg_login)); fLoginId = new BTextControl(aFrame, "Login", "Login:", fLoginSetting->Value(),
new BMessage(msg_login));
fLoginId->SetTarget(this); fLoginId->SetTarget(this);
fLoginId->SetDivider(fLoginId->Divider() - 30); fLoginId->SetDivider(fLoginId->Divider() - 30);
fFtpSetupBox->AddChild(fLoginId); fFtpSetupBox->AddChild(fLoginId);
@@ -749,7 +759,8 @@ VideoWindow::BuildCaptureControls(BView *theView)
aFrame.top = aFrame.bottom + kYBuffer; aFrame.top = aFrame.bottom + kYBuffer;
aFrame.bottom = aFrame.top + kMenuHeight; aFrame.bottom = aFrame.top + kMenuHeight;
fPassword = new BTextControl(aFrame, "Password", "Password:", fPasswordSetting->Value(), new BMessage(msg_password)); fPassword = new BTextControl(aFrame, "Password", "Password:",
fPasswordSetting->Value(), new BMessage(msg_password));
fPassword->SetTarget(this); fPassword->SetTarget(this);
fPassword->SetDivider(fPassword->Divider() - 30); fPassword->SetDivider(fPassword->Divider() - 30);
fFtpSetupBox->AddChild(fPassword); fFtpSetupBox->AddChild(fPassword);
@@ -757,7 +768,8 @@ VideoWindow::BuildCaptureControls(BView *theView)
aFrame.top = aFrame.bottom + kYBuffer; aFrame.top = aFrame.bottom + kYBuffer;
aFrame.bottom = aFrame.top + kMenuHeight; aFrame.bottom = aFrame.top + kMenuHeight;
fDirectory = new BTextControl(aFrame, "Directory", "Directory:", fDirectorySetting->Value(), new BMessage(msg_directory)); fDirectory = new BTextControl(aFrame, "Directory", "Directory:",
fDirectorySetting->Value(), new BMessage(msg_directory));
fDirectory->SetTarget(this); fDirectory->SetTarget(this);
fDirectory->SetDivider(fDirectory->Divider() - 30); fDirectory->SetDivider(fDirectory->Divider() - 30);
fFtpSetupBox->AddChild(fDirectory); fFtpSetupBox->AddChild(fDirectory);
@@ -765,29 +777,29 @@ VideoWindow::BuildCaptureControls(BView *theView)
aFrame.top = aFrame.bottom + kYBuffer; aFrame.top = aFrame.bottom + kYBuffer;
aFrame.bottom = aFrame.top + kMenuHeight; aFrame.bottom = aFrame.top + kMenuHeight;
fPassiveFtp = new BCheckBox(aFrame, "Passive ftp", "Passive ftp", new BMessage(msg_passiveftp)); fPassiveFtp = new BCheckBox(aFrame, "Passive ftp", "Passive ftp",
new BMessage(msg_passiveftp));
fPassiveFtp->SetTarget(this); fPassiveFtp->SetTarget(this);
fPassiveFtp->SetValue(fPassiveFtpSetting->Value()); fPassiveFtp->SetValue(fPassiveFtpSetting->Value());
fFtpSetupBox->AddChild(fPassiveFtp); fFtpSetupBox->AddChild(fPassiveFtp);
aFrame = theView->Bounds(); aFrame = theView->Bounds();
aFrame.top += VIDEO_SIZE_Y + 2*kYBuffer; aFrame.top += VIDEO_SIZE_Y + 2 * kYBuffer;
aFrame.left += kXBuffer; aFrame.left += kXBuffer;
aFrame.right -= kXBuffer; aFrame.right -= kXBuffer;
aFrame.bottom = aFrame.top + kMenuHeight + 2*kYBuffer; aFrame.bottom = aFrame.top + kMenuHeight + 2 * kYBuffer;
fStatusBox = new BBox( aFrame, "Status", B_FOLLOW_ALL, B_WILL_DRAW); fStatusBox = new BBox(aFrame, "Status", B_FOLLOW_ALL, B_WILL_DRAW);
fStatusBox->SetLabel("Status"); fStatusBox->SetLabel("Status");
theView->AddChild(fStatusBox); theView->AddChild(fStatusBox);
aFrame = fStatusBox->Bounds(); aFrame = fStatusBox->Bounds();
aFrame.InsetBy(kXBuffer,kYBuffer); aFrame.InsetBy(kXBuffer, kYBuffer);
fStatusLine = new BStringView(aFrame,"Status Line","Waiting ..."); fStatusLine = new BStringView(aFrame, "Status Line", "Waiting ...");
fStatusBox->AddChild(fStatusLine); fStatusBox->AddChild(fStatusLine);
} }
//---------------------------------------------------------------
void void
VideoWindow::ApplyControls() VideoWindow::ApplyControls()
@@ -803,10 +815,9 @@ VideoWindow::ApplyControls()
fPassiveFtp->Invoke(); fPassiveFtp->Invoke();
} }
//---------------------------------------------------------------
void void
VideoWindow::SetUpSettings(const char *filename, const char *dirname) VideoWindow::_SetUpSettings(const char* filename, const char* dirname)
{ {
fSettings = new Settings(filename, dirname); fSettings = new Settings(filename, dirname);
@@ -819,18 +830,18 @@ VideoWindow::SetUpSettings(const char *filename, const char *dirname)
fSettings->Add(fDirectorySetting = new StringValueSetting("Directory", "web/images", fSettings->Add(fDirectorySetting = new StringValueSetting("Directory", "web/images",
"destination directory expected", "")); "destination directory expected", ""));
fSettings->Add(fPassiveFtpSetting = new BooleanValueSetting("PassiveFtp", 1)); fSettings->Add(fPassiveFtpSetting = new BooleanValueSetting("PassiveFtp", 1));
fSettings->Add(fFilenameSetting = new StringValueSetting("StillImageFilename", "codycam.jpg", fSettings->Add(fFilenameSetting = new StringValueSetting("StillImageFilename",
"still image filename expected", "")); "codycam.jpg", "still image filename expected", ""));
fSettings->Add(fCaptureRateSetting = new EnumeratedStringValueSetting("CaptureRate", "Every 5 minutes", kCaptureRate, fSettings->Add(fCaptureRateSetting = new EnumeratedStringValueSetting("CaptureRate",
"capture rate expected", "unrecognized capture rate specified")); "Every 5 minutes", kCaptureRate, "capture rate expected",
"unrecognized capture rate specified"));
fSettings->TryReadingSettings(); fSettings->TryReadingSettings();
} }
//---------------------------------------------------------------
void void
VideoWindow::QuitSettings() VideoWindow::_QuitSettings()
{ {
fServerSetting->ValueChanged(fServerName->Text()); fServerSetting->ValueChanged(fServerName->Text());
fLoginSetting->ValueChanged(fLoginId->Text()); fLoginSetting->ValueChanged(fLoginId->Text());
@@ -844,13 +855,12 @@ VideoWindow::QuitSettings()
delete fSettings; delete fSettings;
} }
//---------------------------------------------------------------
ControlWindow::ControlWindow( // #pragma mark -
const BRect & frame,
BView * controls,
media_node node) : ControlWindow::ControlWindow(const BRect& frame, BView* controls, media_node node)
BWindow(frame, "Video Preferences", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) : BWindow(frame, "Video Preferences", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
{ {
fView = controls; fView = controls;
fNode = node; fNode = node;
@@ -858,21 +868,19 @@ ControlWindow::ControlWindow(
AddChild(fView); AddChild(fView);
} }
//---------------------------------------------------------------
void void
ControlWindow::MessageReceived(BMessage * message) ControlWindow::MessageReceived(BMessage* message)
{ {
BParameterWeb * web = NULL; BParameterWeb* web = NULL;
status_t err; status_t err;
switch (message->what) switch (message->what) {
{
case B_MEDIA_WEB_CHANGED: case B_MEDIA_WEB_CHANGED:
{ {
// If this is a tab view, find out which tab // If this is a tab view, find out which tab
// is selected // is selected
BTabView *tabView = dynamic_cast<BTabView*>(fView); BTabView* tabView = dynamic_cast<BTabView*>(fView);
int32 tabNum = -1; int32 tabNum = -1;
if (tabView) if (tabView)
tabNum = tabView->Selection(); tabNum = tabView->Selection();
@@ -882,28 +890,25 @@ ControlWindow::MessageReceived(BMessage * message)
err = BMediaRoster::Roster()->GetParameterWebFor(fNode, &web); err = BMediaRoster::Roster()->GetParameterWebFor(fNode, &web);
if ((err >= B_OK) && if (err >= B_OK && web != NULL) {
(web != NULL))
{
fView = BMediaTheme::ViewFor(web); fView = BMediaTheme::ViewFor(web);
AddChild(fView); AddChild(fView);
// Another tab view? Restore previous selection // Another tab view? Restore previous selection
if (tabNum > 0) if (tabNum > 0) {
{ BTabView* newTabView = dynamic_cast<BTabView*>(fView);
BTabView *newTabView = dynamic_cast<BTabView*>(fView);
if (newTabView) if (newTabView)
newTabView->Select(tabNum); newTabView->Select(tabNum);
} }
} }
break; break;
} }
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
} }
} }
//---------------------------------------------------------------
bool bool
ControlWindow::QuitRequested() ControlWindow::QuitRequested()
@@ -913,4 +918,12 @@ ControlWindow::QuitRequested()
} }
// #pragma mark -
int main() {
chdir("/boot/home");
CodyCam app;
app.Run();
return 0;
}
+82 -96
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; BMediaRoster* fMediaRoster;
media_node fTimeSourceNode;
media_node fTimeSourceNode; media_node fProducerNode;
media_node fProducerNode; VideoConsumer* fVideoConsumer;
media_output fProducerOut;
VideoConsumer * fVideoConsumer; media_input fConsumerIn;
BWindow* fWindow;
media_output fProducerOut; port_id fPort;
media_input fConsumerIn; BWindow* fVideoControlWindow;
BWindow * fWindow;
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(); void ApplyControls();
BStringView * StatusLine();
private: BView* VideoView();
void BuildCaptureControls( BStringView* StatusLine();
BView *theView);
void SetUpSettings( private:
const char *filename, void _BuildCaptureControls(BView* theView);
const char *dirname);
void QuitSettings();
void _SetUpSettings(const char* filename, const char* dirname);
void _QuitSettings();
private: private:
media_node * fProducer; media_node* fProducer;
port_id * fPortPtr; port_id* fPortPtr;
BView* fView;
BView* fVideoView;
BView * fView; BTextControl* fFileName;
BView * fVideoView; 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;
BTextControl * fFileName; ftp_msg_info fFtpInfo;
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;
Settings * fSettings; StringValueSetting* fPasswordSetting;
StringValueSetting * fServerSetting; StringValueSetting* fDirectorySetting;
StringValueSetting * fLoginSetting; BooleanValueSetting* fPassiveFtpSetting;
StringValueSetting * fPasswordSetting; StringValueSetting* fFilenameSetting;
StringValueSetting * fDirectorySetting; EnumeratedStringValueSetting* fCaptureRateSetting;
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
+245 -341
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,58 +107,51 @@ 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;
} }
} }
@@ -179,70 +159,58 @@ bool FtpClient::connect(const string &server, const string &login, const string
} }
} }
if(rc == true) if (rc == true)
{ _SetState(ftp_connected);
p_setState(ftp_connected); else {
delete fControl;
} else { fControl = 0;
delete m_control;
m_control = 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";
} }
} }
@@ -268,82 +235,68 @@ bool FtpClient::putFile(const string &local, const string &remote, ftp_mode mode
} }
} }
catch(const char *errstr) catch(const char* errorString)
{ {
} }
delete m_data; delete fData;
m_data = 0; fData = 0;
if(rc == true) if (rc) {
{ _GetReply(replyString, code, codeType);
p_getReply(replystr, code, codetype); rc = codeType <= 2;
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)) if (_SendRequest(cmd))
p_getReply(replystr, code, codetype); _GetReply(replyString, code, codeType);
if (_OpenDataConnection()) {
if(p_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++;
@@ -351,59 +304,49 @@ bool FtpClient::getFile(const string &remote, const string &local, ftp_mode mode
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 m_data; delete fData;
m_data = 0; fData = 0;
if(rc == true) if (rc) {
{ _GetReply(replyString, code, codeType);
p_getReply(replystr, code, codetype); rc = (codeType <= 2 && writeError == false);
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:
@@ -557,148 +492,124 @@ bool FtpClient::p_getReply(string &outstr, int &outcode, int &codetype)
* 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 {
rc = true;
} }
else
rc = true;
return rc; return rc;
} }
+58 -46
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.
@@ -60,3 +21,54 @@ protected:
#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
+104 -77
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
+201 -152
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());
}
#endif
bool bool
Settings::Add(SettingsArgvDispatcher *setting) 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
+98 -92
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); status_t SendArgv(ArgvHandler argvHandlerFunc, void* passThru);
// done with a whole line of argv, send it off and get ready // done with a whole line of argv, send it off and get ready
// to build a new one // to build a new one
void NextArgv(); void NextArgv();
// done with current string, get ready to start building next // done with current string, get ready to start building next
void NextArgvIfNotEmpty(); void NextArgvIfNotEmpty();
// as above, don't commint current string if empty // as above, don't commint current string if empty
void MakeArgvEmpty(); void MakeArgvEmpty();
FILE *file; FILE* fFile;
char *buffer; char* fBuffer;
int32 pos; int32 fPos;
int32 numAvail; int32 fNumAvail;
int argc; int fArgc;
char **currentArgv; char** fCurrentArgv;
int32 currentArgsPos; int32 fCurrentArgsPos;
char currentArgs [1024]; char fCurrentArgs[1024];
bool sawBackslash; bool fSawBackslash;
bool eatComment; bool fEatComment;
bool inDoubleQuote; bool fInDoubleQuote;
bool inSingleQuote; bool fInSingleQuote;
int32 lineNo; int32 fLineNo;
const char *fileName; 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; virtual const char* Handle(const char* const *argv) = 0;
// override this adding an argv parser that reads in the // override this adding an argv parser that reads in the
// values in argv format for this setting // values in argv format for this setting
// return a pointer to an error message or null if parsed OK // return a pointer to an error message or null if parsed OK
bool HandleRectValue(BRect&, const char* const *argv,
bool printError = true);
// some handy reader/writer calls // static bool HandleColorValue(rgb_color &, const char *const *argv, bool printError = true);
bool HandleRectValue(BRect &, const char *const *argv, bool printError = true); void WriteRectValue(Settings*, BRect);
// static bool HandleColorValue(rgb_color &, const char *const *argv, bool printError = true); // void WriteColorValue(BRect);
void WriteRectValue(Settings *, BRect);
// void WriteColorValue(BRect);
protected: protected:
virtual void SaveSettingValue(Settings *settings) = 0; virtual void SaveSettingValue(Settings* settings) = 0;
// override this to save the current value of this setting in a // override this to save the current value of this setting in a
// text format // text format
virtual bool NeedsSaving() const virtual bool NeedsSaving() const
{ return true; } {
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
+105 -133
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: class VideoConsumer : public BMediaEventLooper, public BBufferConsumer {
public:
VideoConsumer(const char* name, BView* view, BStringView* statusLine,
BMediaAddOn *addon, const uint32 internalId);
~VideoConsumer();
virtual void Start(bigtime_t performance_time); /* BMediaNode */
virtual void Stop(bigtime_t performance_time, bool immediate); public:
virtual void Seek(bigtime_t media_time, bigtime_t performance_time); virtual BMediaAddOn* AddOn(long* cookie) const;
virtual void TimeWarp(bigtime_t at_real_time, bigtime_t to_performance_time);
virtual void NodeRegistered(); protected:
virtual status_t RequestCompleted( virtual void Start(bigtime_t performanceTime);
const media_request_info & info); 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 status_t HandleMessage( virtual void NodeRegistered();
int32 message, virtual status_t RequestCompleted(const media_request_info& info);
const void * data,
size_t size);
virtual status_t DeleteHook(BMediaNode * node); virtual status_t HandleMessage(int32 message, const void* data,
size_t size);
/* BMediaEventLooper */ virtual status_t DeleteHook(BMediaNode* node);
protected:
virtual void HandleEvent(
const media_timed_event *event,
bigtime_t lateness,
bool realTimeEvent);
/* BBufferConsumer */
public:
virtual status_t AcceptFormat( /* BMediaEventLooper */
const media_destination &dest, protected:
media_format * format); virtual void HandleEvent(const media_timed_event* event,
virtual status_t GetNextInput( bigtime_t lateness, bool realTimeEvent);
int32 * cookie,
media_input * out_input);
virtual void DisposeInputCookie( /* BBufferConsumer */
int32 cookie); public:
virtual status_t AcceptFormat(const media_destination& dest,
media_format* format);
protected: virtual status_t GetNextInput(int32* cookie, media_input* outInput);
virtual void BufferReceived( virtual void DisposeInputCookie(int32 cookie);
BBuffer * buffer);
private: protected:
virtual void BufferReceived(BBuffer* buffer);
virtual void ProducerDataStatus( private:
const media_destination &for_whom, virtual void ProducerDataStatus(const media_destination &forWhom,
int32 status, int32 status, bigtime_t atMediaTime);
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 */ virtual status_t GetLatencyFor(const media_destination& forWhom,
bigtime_t* outLatency, media_node_id* outId);
public: virtual status_t Connected(const media_source& producer,
status_t CreateBuffers( const media_destination& where, const media_format& withFormat,
const media_format & with_format); media_input* outInput);
void DeleteBuffers(); virtual void Disconnected(const media_source& producer,
const media_destination& where);
static status_t FtpRun( virtual status_t FormatChanged(const media_source& producer,
void *data); const media_destination& consumer, int32 fromChangeCount,
const media_format& format);
void FtpThread( /* implementation */
void);
void UpdateFtpStatus( public:
char *status); status_t CreateBuffers(const media_format& withFormat);
status_t LocalSave( void DeleteBuffers();
char *filename,
BBitmap *bitmap);
status_t FtpSave( static status_t FtpRun(void* data);
char *filename);
private: void FtpThread();
BStringView * mStatusLine; void UpdateFtpStatus(char* status);
uint32 mInternalID;
BMediaAddOn *mAddOn;
thread_id mFtpThread; status_t LocalSave(char* filename, BBitmap* bitmap);
bool mConnectionActive; status_t FtpSave(char* filename);
media_input mIn;
media_destination mDestination;
bigtime_t mMyLatency;
BWindow *mWindow; private:
BView *mView; BStringView* fStatusLine;
BBitmap *mBitmap[3]; uint32 fInternalID;
bool mOurBuffers; BMediaAddOn* fAddOn;
BBufferGroup *mBuffers;
uint32 mBufferMap[3];
BBitmap *mFtpBitmap; thread_id fFtpThread;
volatile bool mTimeToFtp;
volatile bool mFtpComplete;
bigtime_t mRate; bool fConnectionActive;
uint32 mImageFormat; media_input fIn;
int32 mTranslator; media_destination fDestination;
bool mPassiveFtp; bigtime_t fMyLatency;
char mFileNameText[64];
char mServerText[64]; BWindow* fWindow;
char mLoginText[64]; BView* fView;
char mPasswordText[64]; BBitmap* fBitmap[3];
char mDirectoryText[64]; bool fOurBuffers;
BBufferGroup* fBuffers;
uint32 fBufferMap[3];
BBitmap* fFtpBitmap;
volatile bool fTimeToFtp;
volatile bool fFtpComplete;
bigtime_t fRate;
uint32 fImageFormat;
int32 fTranslator;
bool fPassiveFtp;
char fFileNameText[64];
char fServerText[64];
char fLoginText[64];
char fPasswordText[64];
char fDirectoryText[64];
}; };
#endif #endif // VIDEO_CONSUMER_H