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:
+208
-195
@@ -1,23 +1,24 @@
|
||||
#include "CodyCam.h"
|
||||
|
||||
#include <Alert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Button.h>
|
||||
#include <TabView.h>
|
||||
#include <Menu.h>
|
||||
#include <MenuItem.h>
|
||||
#include <MenuBar.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <MediaDefs.h>
|
||||
#include <MediaNode.h>
|
||||
#include <scheduler.h>
|
||||
#include <MediaTheme.h>
|
||||
#include <TimeSource.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 <TimeSource.h>
|
||||
#include <TranslationKit.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#define VIDEO_SIZE_X 320
|
||||
@@ -41,37 +42,90 @@ const int32 kSliderViewRectHeight = 40;
|
||||
const rgb_color kViewGray = {216, 216, 216, 255};
|
||||
|
||||
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 ERROR printf
|
||||
#define FTPINFO printf
|
||||
#define INFO printf
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// The Application
|
||||
//---------------------------------------------------------------
|
||||
|
||||
int main() {
|
||||
chdir("/boot/home");
|
||||
CodyCam app;
|
||||
app.Run();
|
||||
return 0;
|
||||
// Utility functions
|
||||
|
||||
static void
|
||||
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);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
CodyCam::CodyCam() :
|
||||
BApplication("application/x-vnd.Be.CodyCam"),
|
||||
status_t
|
||||
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),
|
||||
fVideoConsumer(NULL),
|
||||
fWindow(NULL),
|
||||
fPort(0),
|
||||
mVideoControlWindow(NULL)
|
||||
fVideoControlWindow(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
CodyCam::~CodyCam()
|
||||
{
|
||||
@@ -87,20 +141,19 @@ CodyCam::~CodyCam()
|
||||
CALL("CodyCam::~CodyCam - EXIT\n");
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
void
|
||||
CodyCam::ReadyToRun()
|
||||
{
|
||||
/* create the window for the app */
|
||||
fWindow = new VideoWindow(BRect(28, 28, 28 + (WINDOW_SIZE_X-1), 28 + (WINDOW_SIZE_Y-1)),
|
||||
(const char *)"CodyCam", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE, &fPort);
|
||||
fWindow = new VideoWindow(BRect(28, 28, 28 + (WINDOW_SIZE_X - 1),
|
||||
28 + (WINDOW_SIZE_Y - 1)), (const char*)"CodyCam", B_TITLED_WINDOW,
|
||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE, &fPort);
|
||||
|
||||
/* set up the node connections */
|
||||
status_t status = SetUpNodes();
|
||||
if (status != B_OK)
|
||||
{
|
||||
// This error is not needed because SetUpNodes handles displaying any
|
||||
status_t status = _SetUpNodes();
|
||||
if (status != B_OK) {
|
||||
// This error is not needed because _SetUpNodes handles displaying any
|
||||
// errors it runs into.
|
||||
// ErrorAlert("Error setting up nodes", status);
|
||||
return;
|
||||
@@ -110,24 +163,22 @@ CodyCam::ReadyToRun()
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
|
||||
bool
|
||||
CodyCam::QuitRequested()
|
||||
{
|
||||
TearDownNodes();
|
||||
_TearDownNodes();
|
||||
snooze(100000);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
void
|
||||
CodyCam::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch (message->what)
|
||||
{
|
||||
switch (message->what) {
|
||||
case msg_start:
|
||||
{
|
||||
BTimeSource* timeSource = fMediaRoster->MakeTimeSourceFor(fTimeSourceNode);
|
||||
@@ -139,57 +190,54 @@ CodyCam::MessageReceived(BMessage *message)
|
||||
timeSource->Release();
|
||||
break;
|
||||
}
|
||||
|
||||
case msg_stop:
|
||||
fMediaRoster->StopNode(fProducerNode, 0, true);
|
||||
break;
|
||||
|
||||
case msg_video:
|
||||
{
|
||||
if (mVideoControlWindow) {
|
||||
mVideoControlWindow->Activate();
|
||||
if (fVideoControlWindow) {
|
||||
fVideoControlWindow->Activate();
|
||||
break;
|
||||
}
|
||||
BParameterWeb* web = NULL;
|
||||
BView* view = NULL;
|
||||
media_node node = fProducerNode;
|
||||
status_t err = fMediaRoster->GetParameterWebFor(node, &web);
|
||||
if ((err >= B_OK) &&
|
||||
(web != NULL))
|
||||
{
|
||||
if (err >= B_OK && web != NULL) {
|
||||
view = BMediaTheme::ViewFor(web);
|
||||
mVideoControlWindow = new ControlWindow(
|
||||
fVideoControlWindow = new ControlWindow(
|
||||
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),
|
||||
view, node);
|
||||
fMediaRoster->StartWatching(BMessenger(NULL, mVideoControlWindow), node, B_MEDIA_WEB_CHANGED);
|
||||
mVideoControlWindow->Show();
|
||||
2 * WINDOW_OFFSET_X + WINDOW_SIZE_X + view->Bounds().right,
|
||||
WINDOW_OFFSET_Y + view->Bounds().bottom), view, node);
|
||||
fMediaRoster->StartWatching(BMessenger(NULL, fVideoControlWindow), node,
|
||||
B_MEDIA_WEB_CHANGED);
|
||||
fVideoControlWindow->Show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case msg_about:
|
||||
{
|
||||
(new BAlert("About CodyCam", "CodyCam\n\nThe Original BeOS WebCam", "Close"))->Go();
|
||||
(new BAlert("About CodyCam", "CodyCam\n\nThe Original BeOS WebCam",
|
||||
"Close"))->Go();
|
||||
break;
|
||||
}
|
||||
|
||||
case msg_control_win:
|
||||
{
|
||||
// our control window is being asked to go away
|
||||
// set our pointer to NULL
|
||||
mVideoControlWindow = NULL;
|
||||
fVideoControlWindow = NULL;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
BApplication::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
status_t
|
||||
CodyCam::SetUpNodes()
|
||||
CodyCam::_SetUpNodes()
|
||||
{
|
||||
status_t status = B_OK;
|
||||
|
||||
@@ -199,12 +247,14 @@ CodyCam::SetUpNodes()
|
||||
ErrorAlert("Can't find the media roster", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* find the time source */
|
||||
status = fMediaRoster->GetTimeSource(&fTimeSourceNode);
|
||||
if (status != B_OK) {
|
||||
ErrorAlert("Can't get a time source", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* find a video producer node */
|
||||
INFO("CodyCam acquiring VideoInput node\n");
|
||||
status = fMediaRoster->GetVideoInput(&fProducerNode);
|
||||
@@ -214,7 +264,8 @@ CodyCam::SetUpNodes()
|
||||
}
|
||||
|
||||
/* 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) {
|
||||
ErrorAlert("Can't create a video window", B_ERROR);
|
||||
return B_ERROR;
|
||||
@@ -230,7 +281,8 @@ CodyCam::SetUpNodes()
|
||||
|
||||
/* find free producer output */
|
||||
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) {
|
||||
status = B_RESOURCE_UNAVAILABLE;
|
||||
ErrorAlert("Can't find an available video stream", status);
|
||||
@@ -239,7 +291,8 @@ CodyCam::SetUpNodes()
|
||||
|
||||
/* find free consumer input */
|
||||
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) {
|
||||
status = B_RESOURCE_UNAVAILABLE;
|
||||
ErrorAlert("Can't find an available connection to the video window", status);
|
||||
@@ -249,8 +302,8 @@ CodyCam::SetUpNodes()
|
||||
/* Connect The Nodes!!! */
|
||||
media_format format;
|
||||
format.type = B_MEDIA_RAW_VIDEO;
|
||||
media_raw_video_format vid_format =
|
||||
{ 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}};
|
||||
media_raw_video_format vid_format = {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}};
|
||||
format.u.raw_video = vid_format;
|
||||
|
||||
/* connect producer to consumer */
|
||||
@@ -261,7 +314,9 @@ CodyCam::SetUpNodes()
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/* set time sources */
|
||||
|
||||
status = fMediaRoster->SetTimeSourceFor(fProducerNode.node, fTimeSourceNode.node);
|
||||
if (status != B_OK) {
|
||||
ErrorAlert("Can't set the timesource for the video source", status);
|
||||
@@ -284,7 +339,9 @@ CodyCam::SetUpNodes()
|
||||
status = fMediaRoster->GetInitialLatencyFor(fProducerNode, &initLatency);
|
||||
if (status < B_OK) {
|
||||
ErrorAlert("error getting initial latency for fCaptureNode", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
initLatency += estimate_max_scheduling_latency();
|
||||
|
||||
BTimeSource* timeSource = fMediaRoster->MakeTimeSourceFor(fProducerNode);
|
||||
@@ -293,8 +350,7 @@ CodyCam::SetUpNodes()
|
||||
/* workaround for people without sound cards */
|
||||
/* because the system time source won't be running */
|
||||
bigtime_t real = BTimeSource::RealTime();
|
||||
if (!running)
|
||||
{
|
||||
if (!running) {
|
||||
status = fMediaRoster->StartTimeSource(fTimeSourceNode, real);
|
||||
if (status != B_OK) {
|
||||
timeSource->Release();
|
||||
@@ -327,17 +383,15 @@ CodyCam::SetUpNodes()
|
||||
return status;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
void
|
||||
CodyCam::TearDownNodes()
|
||||
CodyCam::_TearDownNodes()
|
||||
{
|
||||
CALL("CodyCam::TearDownNodes\n");
|
||||
CALL("CodyCam::_TearDownNodes\n");
|
||||
if (!fMediaRoster)
|
||||
return;
|
||||
|
||||
if (fVideoConsumer)
|
||||
{
|
||||
if (fVideoConsumer) {
|
||||
/* stop */
|
||||
INFO("stopping nodes!\n");
|
||||
// fMediaRoster->StopNode(fProducerNode, 0, true);
|
||||
@@ -357,71 +411,14 @@ CodyCam::TearDownNodes()
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Utility functions
|
||||
//---------------------------------------------------------------
|
||||
|
||||
static void
|
||||
ErrorAlert(const char * message, status_t err)
|
||||
{
|
||||
(new BAlert("", message, "Quit"))->Go();
|
||||
// #pragma mark - Video Window Class
|
||||
|
||||
printf("%s\n%s [%lx]", message, strerror(err), err);
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
status_t
|
||||
AddTranslationItems( BMenu * intoMenu, uint32 from_type)
|
||||
{
|
||||
|
||||
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),
|
||||
VideoWindow::VideoWindow (BRect frame, const char* title, window_type type, uint32 flags,
|
||||
port_id* consumerPort)
|
||||
: BWindow(frame,title,type,flags),
|
||||
fPortPtr(consumerPort),
|
||||
fView(NULL),
|
||||
fVideoView(NULL)
|
||||
{
|
||||
@@ -436,7 +433,7 @@ VideoWindow::VideoWindow (BRect frame, const char *title, window_type type, uint
|
||||
strcpy(fFtpInfo.passwordText, "password");
|
||||
strcpy(fFtpInfo.directoryText, "directory");
|
||||
|
||||
SetUpSettings("codycam", "");
|
||||
_SetUpSettings("codycam", "");
|
||||
|
||||
BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), "menu bar");
|
||||
AddChild(menuBar);
|
||||
@@ -482,7 +479,7 @@ VideoWindow::VideoWindow (BRect frame, const char *title, window_type type, uint
|
||||
AddChild(fView);
|
||||
|
||||
/* add some controls */
|
||||
BuildCaptureControls(fView);
|
||||
_BuildCaptureControls(fView);
|
||||
|
||||
/* add another view to hold the video image */
|
||||
aRect = BRect(0, 0, VIDEO_SIZE_X - 1, VIDEO_SIZE_Y - 1);
|
||||
@@ -494,14 +491,14 @@ VideoWindow::VideoWindow (BRect frame, const char *title, window_type type, uint
|
||||
Show();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
|
||||
VideoWindow::~VideoWindow()
|
||||
{
|
||||
QuitSettings();
|
||||
_QuitSettings();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
|
||||
bool
|
||||
VideoWindow::QuitRequested()
|
||||
@@ -510,122 +507,133 @@ VideoWindow::QuitRequested()
|
||||
return false;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
void
|
||||
VideoWindow::MessageReceived(BMessage* message)
|
||||
{
|
||||
BControl *p;
|
||||
BControl* control;
|
||||
|
||||
p = NULL;
|
||||
message->FindPointer((const char *)"source",(void **)&p);
|
||||
control = NULL;
|
||||
message->FindPointer((const char*)"source", (void **)&control);
|
||||
|
||||
switch (message->what)
|
||||
{
|
||||
switch (message->what) {
|
||||
case msg_filename:
|
||||
if (p != NULL)
|
||||
{
|
||||
strncpy(fFtpInfo.fileNameText, ((BTextControl *)p)->Text(), 63);
|
||||
if (control != NULL) {
|
||||
strncpy(fFtpInfo.fileNameText, ((BTextControl*)control)->Text(), 63);
|
||||
FTPINFO("file is '%s'\n", fFtpInfo.fileNameText);
|
||||
}
|
||||
break;
|
||||
|
||||
case msg_rate_15s:
|
||||
FTPINFO("fifteen seconds\n");
|
||||
fFtpInfo.rate = (bigtime_t)(15 * 1000000);
|
||||
break;
|
||||
|
||||
case msg_rate_30s:
|
||||
FTPINFO("thirty seconds\n");
|
||||
fFtpInfo.rate = (bigtime_t)(30 * 1000000);
|
||||
break;
|
||||
|
||||
case msg_rate_1m:
|
||||
FTPINFO("one minute\n");
|
||||
fFtpInfo.rate = (bigtime_t)(1 * 60 * 1000000);
|
||||
break;
|
||||
|
||||
case msg_rate_5m:
|
||||
FTPINFO("five minute\n");
|
||||
fFtpInfo.rate = (bigtime_t)(5 * 60 * 1000000);
|
||||
break;
|
||||
|
||||
case msg_rate_10m:
|
||||
FTPINFO("ten minute\n");
|
||||
fFtpInfo.rate = (bigtime_t)(10 * 60 * 1000000);
|
||||
break;
|
||||
|
||||
case msg_rate_15m:
|
||||
FTPINFO("fifteen minute\n");
|
||||
fFtpInfo.rate = (bigtime_t)(15 * 60 * 1000000);
|
||||
break;
|
||||
|
||||
case msg_rate_30m:
|
||||
FTPINFO("thirty minute\n");
|
||||
fFtpInfo.rate = (bigtime_t)(30 * 60 * 1000000);
|
||||
break;
|
||||
|
||||
case msg_rate_1h:
|
||||
FTPINFO("one hour\n");
|
||||
fFtpInfo.rate = (bigtime_t)(60LL * 60LL * 1000000LL);
|
||||
break;
|
||||
|
||||
case msg_rate_2h:
|
||||
FTPINFO("two hour\n");
|
||||
fFtpInfo.rate = (bigtime_t)(2LL * 60LL * 60LL * 1000000LL);
|
||||
break;
|
||||
|
||||
case msg_rate_4h:
|
||||
FTPINFO("four hour\n");
|
||||
fFtpInfo.rate = (bigtime_t)(4LL * 60LL * 60LL * 1000000LL);
|
||||
break;
|
||||
|
||||
case msg_rate_8h:
|
||||
FTPINFO("eight hour\n");
|
||||
fFtpInfo.rate = (bigtime_t)(8LL * 60LL * 60LL * 1000000LL);
|
||||
break;
|
||||
|
||||
case msg_rate_24h:
|
||||
FTPINFO("24 hour\n");
|
||||
fFtpInfo.rate = (bigtime_t)(24LL * 60LL * 60LL * 1000000LL);
|
||||
break;
|
||||
|
||||
case msg_rate_never:
|
||||
FTPINFO("never\n");
|
||||
fFtpInfo.rate = (bigtime_t)(B_INFINITE_TIMEOUT);
|
||||
break;
|
||||
|
||||
case msg_translate:
|
||||
message->FindInt32("be:type", (int32*)&(fFtpInfo.imageFormat));
|
||||
message->FindInt32("be:translator", &(fFtpInfo.translator));
|
||||
break;
|
||||
|
||||
case msg_server:
|
||||
if (p != NULL)
|
||||
{
|
||||
strncpy(fFtpInfo.serverText, ((BTextControl *)p)->Text(), 64);
|
||||
if (control != NULL) {
|
||||
strncpy(fFtpInfo.serverText, ((BTextControl*)control)->Text(), 64);
|
||||
FTPINFO("server = '%s'\n", fFtpInfo.serverText);
|
||||
}
|
||||
break;
|
||||
|
||||
case msg_login:
|
||||
if (p != NULL)
|
||||
{
|
||||
strncpy(fFtpInfo.loginText, ((BTextControl *)p)->Text(), 64);
|
||||
if (control != NULL) {
|
||||
strncpy(fFtpInfo.loginText, ((BTextControl*)control)->Text(), 64);
|
||||
FTPINFO("login = '%s'\n", fFtpInfo.loginText);
|
||||
}
|
||||
break;
|
||||
|
||||
case msg_password:
|
||||
if (p != NULL)
|
||||
{
|
||||
strncpy(fFtpInfo.passwordText, ((BTextControl *)p)->Text(), 64);
|
||||
if (control != NULL) {
|
||||
strncpy(fFtpInfo.passwordText, ((BTextControl*)control)->Text(), 64);
|
||||
FTPINFO("password = '%s'\n", fFtpInfo.passwordText);
|
||||
if (Lock())
|
||||
{
|
||||
((BTextControl *)p)->SetText("<HIDDEN>");
|
||||
if (Lock()) {
|
||||
((BTextControl*)control)->SetText("<HIDDEN>");
|
||||
Unlock();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case msg_directory:
|
||||
if (p != NULL)
|
||||
{
|
||||
strncpy(fFtpInfo.directoryText, ((BTextControl *)p)->Text(), 64);
|
||||
if (control != NULL) {
|
||||
strncpy(fFtpInfo.directoryText, ((BTextControl*)control)->Text(), 64);
|
||||
FTPINFO("directory = '%s'\n", fFtpInfo.directoryText);
|
||||
}
|
||||
break;
|
||||
|
||||
case msg_passiveftp:
|
||||
if (p != NULL)
|
||||
{
|
||||
fFtpInfo.passiveFtp = ((BCheckBox *)p)->Value();
|
||||
if (control != NULL) {
|
||||
fFtpInfo.passiveFtp = ((BCheckBox*)control)->Value();
|
||||
if (fFtpInfo.passiveFtp)
|
||||
FTPINFO("using passive ftp\n");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
return;
|
||||
@@ -636,7 +644,6 @@ VideoWindow::MessageReceived(BMessage *message)
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
BView*
|
||||
VideoWindow::VideoView()
|
||||
@@ -644,7 +651,6 @@ VideoWindow::VideoView()
|
||||
return fVideoView;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
BStringView*
|
||||
VideoWindow::StatusLine()
|
||||
@@ -652,10 +658,9 @@ VideoWindow::StatusLine()
|
||||
return fStatusLine;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
void
|
||||
VideoWindow::BuildCaptureControls(BView *theView)
|
||||
VideoWindow::_BuildCaptureControls(BView* theView)
|
||||
{
|
||||
BRect aFrame, theFrame;
|
||||
|
||||
@@ -674,7 +679,8 @@ VideoWindow::BuildCaptureControls(BView *theView)
|
||||
aFrame.top += kYBuffer / 2;
|
||||
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->SetDivider(fFileName->Divider() - 30);
|
||||
@@ -686,10 +692,12 @@ VideoWindow::BuildCaptureControls(BView *theView)
|
||||
fImageFormatMenu = new BPopUpMenu("Image Format Menu");
|
||||
AddTranslationItems(fImageFormatMenu, B_TRANSLATOR_BITMAP);
|
||||
fImageFormatMenu->SetTargetForItems(this);
|
||||
|
||||
if (fImageFormatMenu->FindItem("JPEG Image") != NULL)
|
||||
fImageFormatMenu->FindItem("JPEG Image")->SetMarked(true);
|
||||
else
|
||||
fImageFormatMenu->ItemAt(0)->SetMarked(true);
|
||||
|
||||
fImageFormatSelector = new BMenuField(aFrame, "Format", "Format:", fImageFormatMenu);
|
||||
fImageFormatSelector->SetDivider(fImageFormatSelector->Divider() - 30);
|
||||
fCaptureSetupBox->AddChild(fImageFormatSelector);
|
||||
@@ -733,7 +741,8 @@ VideoWindow::BuildCaptureControls(BView *theView)
|
||||
aFrame.bottom = aFrame.top + kMenuHeight;
|
||||
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->SetDivider(fServerName->Divider() - 30);
|
||||
fFtpSetupBox->AddChild(fServerName);
|
||||
@@ -741,7 +750,8 @@ VideoWindow::BuildCaptureControls(BView *theView)
|
||||
aFrame.top = aFrame.bottom + kYBuffer;
|
||||
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->SetDivider(fLoginId->Divider() - 30);
|
||||
fFtpSetupBox->AddChild(fLoginId);
|
||||
@@ -749,7 +759,8 @@ VideoWindow::BuildCaptureControls(BView *theView)
|
||||
aFrame.top = aFrame.bottom + kYBuffer;
|
||||
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->SetDivider(fPassword->Divider() - 30);
|
||||
fFtpSetupBox->AddChild(fPassword);
|
||||
@@ -757,7 +768,8 @@ VideoWindow::BuildCaptureControls(BView *theView)
|
||||
aFrame.top = aFrame.bottom + kYBuffer;
|
||||
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->SetDivider(fDirectory->Divider() - 30);
|
||||
fFtpSetupBox->AddChild(fDirectory);
|
||||
@@ -765,7 +777,8 @@ VideoWindow::BuildCaptureControls(BView *theView)
|
||||
aFrame.top = aFrame.bottom + kYBuffer;
|
||||
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->SetValue(fPassiveFtpSetting->Value());
|
||||
fFtpSetupBox->AddChild(fPassiveFtp);
|
||||
@@ -787,7 +800,6 @@ VideoWindow::BuildCaptureControls(BView *theView)
|
||||
fStatusBox->AddChild(fStatusLine);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
void
|
||||
VideoWindow::ApplyControls()
|
||||
@@ -803,10 +815,9 @@ VideoWindow::ApplyControls()
|
||||
fPassiveFtp->Invoke();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
void
|
||||
VideoWindow::SetUpSettings(const char *filename, const char *dirname)
|
||||
VideoWindow::_SetUpSettings(const char* filename, const char* 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",
|
||||
"destination directory expected", ""));
|
||||
fSettings->Add(fPassiveFtpSetting = new BooleanValueSetting("PassiveFtp", 1));
|
||||
fSettings->Add(fFilenameSetting = new StringValueSetting("StillImageFilename", "codycam.jpg",
|
||||
"still image filename expected", ""));
|
||||
fSettings->Add(fCaptureRateSetting = new EnumeratedStringValueSetting("CaptureRate", "Every 5 minutes", kCaptureRate,
|
||||
"capture rate expected", "unrecognized capture rate specified"));
|
||||
fSettings->Add(fFilenameSetting = new StringValueSetting("StillImageFilename",
|
||||
"codycam.jpg", "still image filename expected", ""));
|
||||
fSettings->Add(fCaptureRateSetting = new EnumeratedStringValueSetting("CaptureRate",
|
||||
"Every 5 minutes", kCaptureRate, "capture rate expected",
|
||||
"unrecognized capture rate specified"));
|
||||
|
||||
fSettings->TryReadingSettings();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
void
|
||||
VideoWindow::QuitSettings()
|
||||
VideoWindow::_QuitSettings()
|
||||
{
|
||||
fServerSetting->ValueChanged(fServerName->Text());
|
||||
fLoginSetting->ValueChanged(fLoginId->Text());
|
||||
@@ -844,13 +855,12 @@ VideoWindow::QuitSettings()
|
||||
delete fSettings;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
ControlWindow::ControlWindow(
|
||||
const BRect & frame,
|
||||
BView * controls,
|
||||
media_node node) :
|
||||
BWindow(frame, "Video Preferences", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
ControlWindow::ControlWindow(const BRect& frame, BView* controls, media_node node)
|
||||
: BWindow(frame, "Video Preferences", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
||||
{
|
||||
fView = controls;
|
||||
fNode = node;
|
||||
@@ -858,7 +868,6 @@ ControlWindow::ControlWindow(
|
||||
AddChild(fView);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
void
|
||||
ControlWindow::MessageReceived(BMessage* message)
|
||||
@@ -866,8 +875,7 @@ ControlWindow::MessageReceived(BMessage * message)
|
||||
BParameterWeb* web = NULL;
|
||||
status_t err;
|
||||
|
||||
switch (message->what)
|
||||
{
|
||||
switch (message->what) {
|
||||
case B_MEDIA_WEB_CHANGED:
|
||||
{
|
||||
// If this is a tab view, find out which tab
|
||||
@@ -882,15 +890,12 @@ ControlWindow::MessageReceived(BMessage * message)
|
||||
|
||||
err = BMediaRoster::Roster()->GetParameterWebFor(fNode, &web);
|
||||
|
||||
if ((err >= B_OK) &&
|
||||
(web != NULL))
|
||||
{
|
||||
if (err >= B_OK && web != NULL) {
|
||||
fView = BMediaTheme::ViewFor(web);
|
||||
AddChild(fView);
|
||||
|
||||
// Another tab view? Restore previous selection
|
||||
if (tabNum > 0)
|
||||
{
|
||||
if (tabNum > 0) {
|
||||
BTabView* newTabView = dynamic_cast<BTabView*>(fView);
|
||||
if (newTabView)
|
||||
newTabView->Select(tabNum);
|
||||
@@ -898,12 +903,12 @@ ControlWindow::MessageReceived(BMessage * message)
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
bool
|
||||
ControlWindow::QuitRequested()
|
||||
@@ -913,4 +918,12 @@ ControlWindow::QuitRequested()
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
int main() {
|
||||
chdir("/boot/home");
|
||||
CodyCam app;
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
+28
-42
@@ -1,21 +1,23 @@
|
||||
/* CodyCam.h */
|
||||
|
||||
#ifndef 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 "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;
|
||||
|
||||
@@ -56,6 +58,7 @@ enum {
|
||||
msg_control_win = 'ctlw'
|
||||
};
|
||||
|
||||
|
||||
const char* kCaptureRate[] = {
|
||||
"Every 15 seconds",
|
||||
"Every 30 seconds",
|
||||
@@ -73,6 +76,7 @@ const char *kCaptureRate[] = {
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
class CodyCam : public BApplication {
|
||||
public:
|
||||
CodyCam();
|
||||
@@ -80,44 +84,32 @@ class CodyCam : public BApplication {
|
||||
|
||||
void ReadyToRun();
|
||||
virtual bool QuitRequested();
|
||||
virtual void MessageReceived(
|
||||
BMessage *message);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
status_t SetUpNodes();
|
||||
void TearDownNodes();
|
||||
status_t _SetUpNodes();
|
||||
void _TearDownNodes();
|
||||
|
||||
BMediaRoster* fMediaRoster;
|
||||
|
||||
media_node fTimeSourceNode;
|
||||
media_node fProducerNode;
|
||||
|
||||
VideoConsumer* fVideoConsumer;
|
||||
|
||||
media_output fProducerOut;
|
||||
media_input fConsumerIn;
|
||||
|
||||
BWindow* fWindow;
|
||||
|
||||
port_id fPort;
|
||||
|
||||
BWindow *mVideoControlWindow;
|
||||
BWindow* fVideoControlWindow;
|
||||
};
|
||||
|
||||
class VideoWindow : public BWindow
|
||||
{
|
||||
|
||||
class VideoWindow : public BWindow {
|
||||
public:
|
||||
VideoWindow (
|
||||
BRect frame,
|
||||
const char * title,
|
||||
window_type type,
|
||||
uint32 flags,
|
||||
port_id * consumerport);
|
||||
VideoWindow(BRect frame, const char* title, window_type type,
|
||||
uint32 flags, port_id* consumerport);
|
||||
~VideoWindow();
|
||||
|
||||
virtual bool QuitRequested();
|
||||
virtual void MessageReceived(
|
||||
BMessage *message);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
void ApplyControls();
|
||||
|
||||
@@ -125,20 +117,15 @@ public:
|
||||
BStringView* StatusLine();
|
||||
|
||||
private:
|
||||
void BuildCaptureControls(
|
||||
BView *theView);
|
||||
|
||||
void SetUpSettings(
|
||||
const char *filename,
|
||||
const char *dirname);
|
||||
void QuitSettings();
|
||||
void _BuildCaptureControls(BView* theView);
|
||||
|
||||
void _SetUpSettings(const char* filename, const char* dirname);
|
||||
void _QuitSettings();
|
||||
|
||||
private:
|
||||
media_node* fProducer;
|
||||
port_id* fPortPtr;
|
||||
|
||||
|
||||
BView* fView;
|
||||
BView* fVideoView;
|
||||
|
||||
@@ -159,7 +146,6 @@ private:
|
||||
|
||||
ftp_msg_info fFtpInfo;
|
||||
|
||||
|
||||
Settings* fSettings;
|
||||
StringValueSetting* fServerSetting;
|
||||
StringValueSetting* fLoginSetting;
|
||||
@@ -170,8 +156,8 @@ private:
|
||||
EnumeratedStringValueSetting* fCaptureRateSetting;
|
||||
};
|
||||
|
||||
class ControlWindow : public BWindow {
|
||||
|
||||
class ControlWindow : public BWindow {
|
||||
public:
|
||||
ControlWindow(const BRect& frame, BView* controls, media_node node);
|
||||
void MessageReceived(BMessage* message);
|
||||
@@ -182,4 +168,4 @@ private:
|
||||
media_node fNode;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // CODYCAM_H
|
||||
|
||||
+225
-321
@@ -1,38 +1,36 @@
|
||||
#include "FtpClient.h"
|
||||
|
||||
FtpClient::FtpClient()
|
||||
:
|
||||
fState(0),
|
||||
fControl(NULL),
|
||||
fData(NULL)
|
||||
{
|
||||
m_control = 0;
|
||||
m_state = 0;
|
||||
m_data = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
FtpClient::~FtpClient()
|
||||
{
|
||||
delete m_control;
|
||||
delete m_data;
|
||||
delete fControl;
|
||||
delete fData;
|
||||
}
|
||||
|
||||
|
||||
bool FtpClient::cd(const string &dir)
|
||||
bool
|
||||
FtpClient::ChangeDir(const string& dir)
|
||||
{
|
||||
bool rc = false;
|
||||
int code, codetype;
|
||||
string cmd = "CWD ", replystr;
|
||||
|
||||
int code, codeType;
|
||||
string cmd = "CWD ", replyString;
|
||||
|
||||
cmd += dir;
|
||||
|
||||
if (dir.length() == 0)
|
||||
cmd += '/';
|
||||
|
||||
if(p_sendRequest(cmd) == true)
|
||||
{
|
||||
if(p_getReply(replystr, code, codetype) == true)
|
||||
{
|
||||
if(codetype == 2)
|
||||
if (_SendRequest(cmd) == true) {
|
||||
if (_GetReply(replyString, code, codeType) == true) {
|
||||
if (codeType == 2)
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
@@ -40,42 +38,35 @@ bool FtpClient::cd(const string &dir)
|
||||
}
|
||||
|
||||
|
||||
bool FtpClient::ls(string &listing)
|
||||
bool
|
||||
FtpClient::ListDirContents(string& listing)
|
||||
{
|
||||
bool rc = false;
|
||||
string cmd, replystr;
|
||||
int code, codetype, numread;
|
||||
string cmd, replyString;
|
||||
int code, codeType, numRead;
|
||||
char buf[513];
|
||||
|
||||
cmd = "TYPE A";
|
||||
|
||||
if(p_sendRequest(cmd))
|
||||
p_getReply(replystr, code, codetype);
|
||||
if (_SendRequest(cmd))
|
||||
_GetReply(replyString, code, codeType);
|
||||
|
||||
if(p_openDataConnection())
|
||||
{
|
||||
if (_OpenDataConnection()) {
|
||||
cmd = "LIST";
|
||||
|
||||
if(p_sendRequest(cmd))
|
||||
{
|
||||
if(p_getReply(replystr, code, codetype))
|
||||
{
|
||||
if(codetype <= 2)
|
||||
{
|
||||
if(p_acceptDataConnection())
|
||||
{
|
||||
numread = 1;
|
||||
while(numread > 0)
|
||||
{
|
||||
if (_SendRequest(cmd)) {
|
||||
if (_GetReply(replyString, code, codeType)) {
|
||||
if (codeType <= 2) {
|
||||
if (_AcceptDataConnection()) {
|
||||
numRead = 1;
|
||||
while (numRead > 0) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
numread = m_data->Receive(buf, sizeof(buf) - 1);
|
||||
numRead = fData->Receive(buf, sizeof(buf) - 1);
|
||||
listing += buf;
|
||||
printf(buf);
|
||||
}
|
||||
if(p_getReply(replystr, code, codetype))
|
||||
{
|
||||
if(codetype <= 2)
|
||||
{
|
||||
if (_GetReply(replyString, code, codeType)) {
|
||||
if (codeType <= 2)
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
@@ -83,33 +74,29 @@ bool FtpClient::ls(string &listing)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete m_data;
|
||||
m_data = 0;
|
||||
delete fData;
|
||||
fData = 0;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
bool FtpClient::pwd(string &dir)
|
||||
bool
|
||||
FtpClient::PrintWorkingDir(string& dir)
|
||||
{
|
||||
bool rc = false;
|
||||
int code, codetype;
|
||||
string cmd = "PWD", replystr;
|
||||
int code, codeType;
|
||||
string cmd = "PWD", replyString;
|
||||
long i;
|
||||
|
||||
if(p_sendRequest(cmd) == true)
|
||||
{
|
||||
if(p_getReply(replystr, code, codetype) == true)
|
||||
{
|
||||
if(codetype == 2)
|
||||
{
|
||||
i = replystr.find('"');
|
||||
if(i != -1)
|
||||
{
|
||||
if (_SendRequest(cmd) == true) {
|
||||
if (_GetReply(replyString, code, codeType) == true) {
|
||||
if (codeType == 2) {
|
||||
i = replyString.find('"');
|
||||
if (i != -1) {
|
||||
i++;
|
||||
dir = replystr.substr(i, replystr.find('"') - i);
|
||||
dir = replyString.substr(i, replyString.find('"') - i);
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
@@ -120,54 +107,47 @@ 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;
|
||||
int code, codetype;
|
||||
string cmd, replystr;
|
||||
int code, codeType;
|
||||
string cmd, replyString;
|
||||
BNetAddress addr;
|
||||
|
||||
delete m_control;
|
||||
delete m_data;
|
||||
delete fControl;
|
||||
delete fData;
|
||||
|
||||
fControl = new BNetEndpoint;
|
||||
|
||||
m_control = new BNetEndpoint;
|
||||
|
||||
if(m_control->InitCheck() != B_NO_ERROR)
|
||||
if (fControl->InitCheck() != B_NO_ERROR)
|
||||
return false;
|
||||
|
||||
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
|
||||
//
|
||||
|
||||
if(p_getReply(replystr, code, codetype))
|
||||
{
|
||||
if(code != 421 && codetype != 5)
|
||||
{
|
||||
cmd = "USER "; cmd += login;
|
||||
p_sendRequest(cmd);
|
||||
if(p_getReply(replystr, code, codetype))
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
if (_GetReply(replyString, code, codeType)) {
|
||||
if (code != 421 && codeType != 5) {
|
||||
cmd = "USER ";
|
||||
cmd += login;
|
||||
_SendRequest(cmd);
|
||||
|
||||
if (_GetReply(replyString, code, codeType)) {
|
||||
switch (code) {
|
||||
case 230:
|
||||
case 202:
|
||||
rc = true;
|
||||
break;
|
||||
|
||||
case 331: // password needed
|
||||
cmd = "PASS "; cmd += passwd;
|
||||
p_sendRequest(cmd);
|
||||
if(p_getReply(replystr, code, codetype))
|
||||
{
|
||||
if(codetype == 2)
|
||||
{
|
||||
cmd = "PASS ";
|
||||
cmd += passwd;
|
||||
_SendRequest(cmd);
|
||||
if (_GetReply(replyString, code, codeType)) {
|
||||
if (codeType == 2)
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -180,24 +160,22 @@ bool FtpClient::connect(const string &server, const string &login, const string
|
||||
}
|
||||
|
||||
if (rc == true)
|
||||
{
|
||||
p_setState(ftp_connected);
|
||||
|
||||
} else {
|
||||
delete m_control;
|
||||
m_control = 0;
|
||||
_SetState(ftp_connected);
|
||||
else {
|
||||
delete fControl;
|
||||
fControl = 0;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool FtpClient::putFile(const string &local, const string &remote, ftp_mode mode)
|
||||
bool
|
||||
FtpClient::PutFile(const string& local, const string& remote, ftp_mode mode)
|
||||
{
|
||||
bool rc = false;
|
||||
string cmd, replystr;
|
||||
int code, codetype, rlen, slen, i;
|
||||
string cmd, replyString;
|
||||
int code, codeType, rlen, slen, i;
|
||||
BFile infile(local.c_str(), B_READ_ONLY);
|
||||
char buf[8192], sbuf[16384], *stmp;
|
||||
|
||||
@@ -209,40 +187,30 @@ bool FtpClient::putFile(const string &local, const string &remote, ftp_mode mode
|
||||
else
|
||||
cmd = "TYPE A";
|
||||
|
||||
if(p_sendRequest(cmd))
|
||||
p_getReply(replystr, code, codetype);
|
||||
if (_SendRequest(cmd))
|
||||
_GetReply(replyString, code, codeType);
|
||||
|
||||
try
|
||||
{
|
||||
if(p_openDataConnection())
|
||||
{
|
||||
try {
|
||||
if (_OpenDataConnection()) {
|
||||
cmd = "STOR ";
|
||||
cmd += remote;
|
||||
|
||||
if(p_sendRequest(cmd))
|
||||
{
|
||||
if(p_getReply(replystr, code, codetype))
|
||||
{
|
||||
if(codetype <= 2)
|
||||
{
|
||||
if(p_acceptDataConnection())
|
||||
{
|
||||
if (_SendRequest(cmd)) {
|
||||
if (_GetReply(replyString, code, codeType)) {
|
||||
if (codeType <= 2) {
|
||||
if (_AcceptDataConnection()) {
|
||||
rlen = 1;
|
||||
while(rlen > 0)
|
||||
{
|
||||
while (rlen > 0) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(sbuf, 0, sizeof(sbuf));
|
||||
rlen = infile.Read((void*)buf, sizeof(buf));
|
||||
slen = rlen;
|
||||
stmp = buf;
|
||||
if(mode == ascii_mode)
|
||||
{
|
||||
if (mode == ascii_mode) {
|
||||
stmp = sbuf;
|
||||
slen = 0;
|
||||
for(i=0;i<rlen;i++)
|
||||
{
|
||||
if(buf[i] == '\n')
|
||||
{
|
||||
for (i = 0; i < rlen; i++) {
|
||||
if (buf[i] == '\n') {
|
||||
*stmp = '\r';
|
||||
stmp++;
|
||||
slen++;
|
||||
@@ -253,9 +221,8 @@ bool FtpClient::putFile(const string &local, const string &remote, ftp_mode mode
|
||||
}
|
||||
stmp = sbuf;
|
||||
}
|
||||
if(slen > 0)
|
||||
{
|
||||
if(m_data->Send(stmp, slen) < 0)
|
||||
if (slen > 0) {
|
||||
if (fData->Send(stmp, slen) < 0)
|
||||
throw "bail";
|
||||
}
|
||||
}
|
||||
@@ -268,33 +235,31 @@ bool FtpClient::putFile(const string &local, const string &remote, ftp_mode mode
|
||||
}
|
||||
}
|
||||
|
||||
catch(const char *errstr)
|
||||
catch(const char* errorString)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
delete m_data;
|
||||
m_data = 0;
|
||||
delete fData;
|
||||
fData = 0;
|
||||
|
||||
if(rc == true)
|
||||
{
|
||||
p_getReply(replystr, code, codetype);
|
||||
rc = (bool) codetype <= 2;
|
||||
if (rc) {
|
||||
_GetReply(replyString, code, codeType);
|
||||
rc = codeType <= 2;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool FtpClient::getFile(const string &remote, const string &local, ftp_mode mode)
|
||||
bool
|
||||
FtpClient::GetFile(const string& remote, const string& local, ftp_mode mode)
|
||||
{
|
||||
bool rc = false;
|
||||
string cmd, replystr;
|
||||
int code, codetype, rlen, slen, i;
|
||||
string cmd, replyString;
|
||||
int code, codeType, rlen, slen, i;
|
||||
BFile outfile(local.c_str(), B_READ_WRITE | B_CREATE_FILE);
|
||||
char buf[8192], sbuf[16384], *stmp;
|
||||
bool writeerr = false;
|
||||
bool writeError = false;
|
||||
|
||||
if (outfile.InitCheck() != B_NO_ERROR)
|
||||
return false;
|
||||
@@ -304,46 +269,34 @@ bool FtpClient::getFile(const string &remote, const string &local, ftp_mode mode
|
||||
else
|
||||
cmd = "TYPE A";
|
||||
|
||||
if(p_sendRequest(cmd))
|
||||
p_getReply(replystr, code, codetype);
|
||||
if (_SendRequest(cmd))
|
||||
_GetReply(replyString, code, codeType);
|
||||
|
||||
|
||||
if(p_openDataConnection())
|
||||
{
|
||||
if (_OpenDataConnection()) {
|
||||
cmd = "RETR ";
|
||||
cmd += remote;
|
||||
|
||||
if(p_sendRequest(cmd))
|
||||
{
|
||||
if(p_getReply(replystr, code, codetype))
|
||||
{
|
||||
if(codetype <= 2)
|
||||
{
|
||||
if(p_acceptDataConnection())
|
||||
{
|
||||
if (_SendRequest(cmd)) {
|
||||
if (_GetReply(replyString, code, codeType)) {
|
||||
if (codeType <= 2) {
|
||||
if (_AcceptDataConnection()) {
|
||||
rlen = 1;
|
||||
rc = true;
|
||||
while(rlen > 0)
|
||||
{
|
||||
while (rlen > 0) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
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;
|
||||
stmp = buf;
|
||||
if(mode == ascii_mode)
|
||||
{
|
||||
if (mode == ascii_mode) {
|
||||
stmp = sbuf;
|
||||
slen = 0;
|
||||
for(i=0;i<rlen;i++)
|
||||
{
|
||||
for (i = 0; i < rlen; i++) {
|
||||
if (buf[i] == '\r')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
*stmp = buf[i];
|
||||
stmp++;
|
||||
slen++;
|
||||
@@ -351,59 +304,49 @@ bool FtpClient::getFile(const string &remote, const string &local, ftp_mode mode
|
||||
stmp = sbuf;
|
||||
}
|
||||
|
||||
if(slen > 0)
|
||||
{
|
||||
if (slen > 0) {
|
||||
if (outfile.Write(stmp, slen) < 0)
|
||||
{
|
||||
writeerr = true;
|
||||
writeError = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete m_data;
|
||||
m_data = 0;
|
||||
delete fData;
|
||||
fData = 0;
|
||||
|
||||
if(rc == true)
|
||||
{
|
||||
p_getReply(replystr, code, codetype);
|
||||
rc = (bool) ((codetype <= 2) && (writeerr == false));
|
||||
if (rc) {
|
||||
_GetReply(replyString, code, codeType);
|
||||
rc = (codeType <= 2 && writeError == false);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
// Note: this only works for local remote moves, cross filesystem moves
|
||||
// will not work
|
||||
//
|
||||
bool FtpClient::moveFile(const string &oldpath, const string &newpath)
|
||||
bool
|
||||
FtpClient::MoveFile(const string& oldPath, const string& newPath)
|
||||
{
|
||||
bool rc = false;
|
||||
string from = "RNFR ";
|
||||
string to = "RNTO ";
|
||||
string replystr;
|
||||
int code, codetype;
|
||||
string replyString;
|
||||
int code, codeType;
|
||||
|
||||
from += oldpath;
|
||||
to += newpath;
|
||||
from += oldPath;
|
||||
to += newPath;
|
||||
|
||||
if(p_sendRequest(from))
|
||||
{
|
||||
if(p_getReply(replystr, code, codetype))
|
||||
{
|
||||
if(codetype == 3)
|
||||
{
|
||||
if(p_sendRequest(to))
|
||||
{
|
||||
if(p_getReply(replystr, code, codetype))
|
||||
{
|
||||
if(codetype == 2)
|
||||
if (_SendRequest(from)) {
|
||||
if (_GetReply(replyString, code, codeType)) {
|
||||
if (codeType == 3) {
|
||||
if (_SendRequest(to)) {
|
||||
if (_GetReply(replyString, code, codeType)) {
|
||||
if(codeType == 2)
|
||||
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)
|
||||
p_setState(ftp_passive);
|
||||
_SetState(ftp_passive);
|
||||
else
|
||||
p_clearState(ftp_passive);
|
||||
_ClearState(ftp_passive);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool FtpClient::p_testState(unsigned long state)
|
||||
bool
|
||||
FtpClient::_TestState(unsigned long state)
|
||||
{
|
||||
return (bool) ((m_state & state) != 0);
|
||||
return ((fState & state) != 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FtpClient::p_setState(unsigned long state)
|
||||
void
|
||||
FtpClient::_SetState(unsigned long state)
|
||||
{
|
||||
m_state |= state;
|
||||
fState |= state;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FtpClient::p_clearState(unsigned long state)
|
||||
void
|
||||
FtpClient::_ClearState(unsigned long state)
|
||||
{
|
||||
m_state &= ~state;
|
||||
fState &= ~state;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool FtpClient::p_sendRequest(const string &cmd)
|
||||
bool
|
||||
FtpClient::_SendRequest(const string& cmd)
|
||||
{
|
||||
bool rc = false;
|
||||
string ccmd = cmd;
|
||||
|
||||
if(m_control != 0)
|
||||
{
|
||||
if (fControl != 0) {
|
||||
if (cmd.find("PASS") != string::npos)
|
||||
printf("PASS <suppressed> (real password sent)\n");
|
||||
else
|
||||
printf("%s\n", ccmd.c_str());
|
||||
|
||||
ccmd += "\r\n";
|
||||
if(m_control->Send(ccmd.c_str(), ccmd.length()) >= 0)
|
||||
{
|
||||
if (fControl->Send(ccmd.c_str(), ccmd.length()) >= 0)
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool FtpClient::p_getReplyLine(string &line)
|
||||
bool
|
||||
FtpClient::_GetReplyLine(string& line)
|
||||
{
|
||||
bool rc = false;
|
||||
int c = 0;
|
||||
@@ -477,38 +418,33 @@ bool FtpClient::p_getReplyLine(string &line)
|
||||
|
||||
line = ""; // Thanks to Stephen van Egmond for catching a bug here
|
||||
|
||||
if(m_control != 0)
|
||||
{
|
||||
if (fControl != 0) {
|
||||
rc = true;
|
||||
while(done == false && (m_control->Receive(&c, 1) > 0))
|
||||
{
|
||||
if(c == EOF || c == xEOF || c == '\n')
|
||||
{
|
||||
while (done == false && fControl->Receive(&c, 1) > 0) {
|
||||
if (c == EOF || c == xEOF || c == '\n') {
|
||||
done = true;
|
||||
} else {
|
||||
if(c == IAC)
|
||||
{
|
||||
m_control->Receive(&c, 1);
|
||||
switch(c)
|
||||
{
|
||||
if (c == IAC) {
|
||||
fControl->Receive(&c, 1);
|
||||
switch (c) {
|
||||
unsigned char treply[3];
|
||||
case WILL:
|
||||
case WONT:
|
||||
m_control->Receive(&c, 1);
|
||||
fControl->Receive(&c, 1);
|
||||
treply[0] = IAC;
|
||||
treply[1] = DONT;
|
||||
treply[2] = c;
|
||||
m_control->Send(treply, 3);
|
||||
fControl->Send(treply, 3);
|
||||
break;
|
||||
|
||||
case DO:
|
||||
case DONT:
|
||||
m_control->Receive(&c, 1);
|
||||
m_control->Receive(&c, 1);
|
||||
fControl->Receive(&c, 1);
|
||||
fControl->Receive(&c, 1);
|
||||
treply[0] = IAC;
|
||||
treply[1] = WONT;
|
||||
treply[2] = c;
|
||||
m_control->Send(treply, 3);
|
||||
fControl->Send(treply, 3);
|
||||
break;
|
||||
|
||||
case EOF:
|
||||
@@ -521,9 +457,7 @@ bool FtpClient::p_getReplyLine(string &line)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// normal char
|
||||
//
|
||||
if (c != '\r')
|
||||
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;
|
||||
string line, tempstr;
|
||||
string line, tempString;
|
||||
|
||||
//
|
||||
// comment from the ncftp source:
|
||||
@@ -557,134 +492,111 @@ bool FtpClient::p_getReply(string &outstr, int &outcode, int &codetype)
|
||||
* 123 The last line
|
||||
*/
|
||||
|
||||
if((rc = p_getReplyLine(line)) == true)
|
||||
{
|
||||
outstr = line;
|
||||
outstr += '\n';
|
||||
printf(outstr.c_str());
|
||||
tempstr = line.substr(0, 3);
|
||||
outcode = atoi(tempstr.c_str());
|
||||
if ((rc = _GetReplyLine(line)) == true) {
|
||||
outString = line;
|
||||
outString += '\n';
|
||||
printf(outString.c_str());
|
||||
tempString = line.substr(0, 3);
|
||||
outCode = atoi(tempString.c_str());
|
||||
|
||||
if(line[3] == '-')
|
||||
{
|
||||
while((rc = p_getReplyLine(line)) == true)
|
||||
{
|
||||
outstr += line;
|
||||
outstr += '\n';
|
||||
printf(outstr.c_str());
|
||||
//
|
||||
if (line[3] == '-') {
|
||||
while ((rc = _GetReplyLine(line)) == true) {
|
||||
outString += line;
|
||||
outString += '\n';
|
||||
printf(outString.c_str());
|
||||
// we're done with nnn when we get to a "nnn blahblahblah"
|
||||
//
|
||||
if((line.find(tempstr) == 0) && line[3] == ' ')
|
||||
if ((line.find(tempString) == 0) && line[3] == ' ')
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(rc == false && outcode != 421)
|
||||
{
|
||||
outstr += "Remote host has closed the connection.\n";
|
||||
outcode = 421;
|
||||
if (!rc && outCode != 421) {
|
||||
outString += "Remote host has closed the connection.\n";
|
||||
outCode = 421;
|
||||
}
|
||||
|
||||
if(outcode == 421)
|
||||
{
|
||||
delete m_control;
|
||||
m_control = 0;
|
||||
p_clearState(ftp_connected);
|
||||
if (outCode == 421) {
|
||||
delete fControl;
|
||||
fControl = 0;
|
||||
_ClearState(ftp_connected);
|
||||
}
|
||||
|
||||
codetype = outcode / 100;
|
||||
codeType = outCode / 100;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool FtpClient::p_openDataConnection()
|
||||
bool
|
||||
FtpClient::_OpenDataConnection()
|
||||
{
|
||||
string host, cmd, repstr;
|
||||
string host, cmd, replyString;
|
||||
unsigned short port;
|
||||
BNetAddress addr;
|
||||
int i, code, codetype;
|
||||
int i, code, codeType;
|
||||
bool rc = false;
|
||||
struct sockaddr_in sa;
|
||||
|
||||
delete m_data;
|
||||
m_data = 0;
|
||||
delete fData;
|
||||
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
|
||||
// on the port it sends back to us
|
||||
//
|
||||
cmd = "PASV";
|
||||
if(p_sendRequest(cmd))
|
||||
{
|
||||
if(p_getReply(repstr, code, codetype))
|
||||
{
|
||||
if (_SendRequest(cmd)) {
|
||||
if (_GetReply(replyString, code, codeType)) {
|
||||
|
||||
if(codetype == 2)
|
||||
{
|
||||
if (codeType == 2) {
|
||||
// It should give us something like:
|
||||
// "227 Entering Passive Mode (192,168,1,1,10,187)"
|
||||
int paddr[6];
|
||||
unsigned char ucaddr[6];
|
||||
|
||||
i = repstr.find('(');
|
||||
i = replyString.find('(');
|
||||
i++;
|
||||
|
||||
repstr = repstr.substr(i, repstr.find(')') - i);
|
||||
if (sscanf(repstr.c_str(), "%d,%d,%d,%d,%d,%d",
|
||||
replyString = replyString.substr(i, replyString.find(')') - i);
|
||||
if (sscanf(replyString.c_str(), "%d,%d,%d,%d,%d,%d",
|
||||
&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
|
||||
//
|
||||
p_clearState(ftp_passive);
|
||||
return p_openDataConnection();
|
||||
_ClearState(ftp_passive);
|
||||
return _OpenDataConnection();
|
||||
}
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
ucaddr[i] = (unsigned char)(paddr[i] & 0xff);
|
||||
}
|
||||
|
||||
memcpy(&sa.sin_addr, &ucaddr[0], (size_t) 4);
|
||||
memcpy(&sa.sin_port, &ucaddr[4], (size_t) 2);
|
||||
addr.SetTo(sa);
|
||||
if(m_data->Connect(addr) == B_NO_ERROR)
|
||||
{
|
||||
if (fData->Connect(addr) == B_NO_ERROR)
|
||||
rc = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// cannot do passive. Do a little harmless rercursion here
|
||||
//
|
||||
p_clearState(ftp_passive);
|
||||
rc = p_openDataConnection();
|
||||
_ClearState(ftp_passive);
|
||||
rc = _OpenDataConnection();
|
||||
}
|
||||
|
||||
} else {
|
||||
//
|
||||
// Here we bind to a local port and send a PORT command
|
||||
//
|
||||
if(m_data->Bind() == B_NO_ERROR)
|
||||
{
|
||||
if (fData->Bind() == B_NO_ERROR) {
|
||||
char buf[255];
|
||||
|
||||
m_data->Listen();
|
||||
addr = m_data->LocalAddr();
|
||||
fData->Listen();
|
||||
addr = fData->LocalAddr();
|
||||
addr.GetAddr(buf, &port);
|
||||
host = buf;
|
||||
|
||||
i = 0;
|
||||
while(i >= 0)
|
||||
{
|
||||
while (i >= 0) {
|
||||
i = host.find('.', i);
|
||||
if (i >= 0)
|
||||
host[i] = ',';
|
||||
@@ -692,13 +604,12 @@ bool FtpClient::p_openDataConnection()
|
||||
|
||||
sprintf(buf, ",%d,%d", (port & 0xff00) >> 8, port & 0x00ff);
|
||||
cmd = "PORT ";
|
||||
cmd += host; cmd += buf;
|
||||
p_sendRequest(cmd);
|
||||
p_getReply(repstr, code, codetype);
|
||||
//
|
||||
cmd += host;
|
||||
cmd += buf;
|
||||
_SendRequest(cmd);
|
||||
_GetReply(replyString, code, codeType);
|
||||
// PORT failure is in the 500-range
|
||||
//
|
||||
if(codetype == 2)
|
||||
if (codeType == 2)
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
@@ -707,32 +618,25 @@ bool FtpClient::p_openDataConnection()
|
||||
}
|
||||
|
||||
|
||||
bool FtpClient::p_acceptDataConnection()
|
||||
bool
|
||||
FtpClient::_AcceptDataConnection()
|
||||
{
|
||||
BNetEndpoint *ep;
|
||||
BNetEndpoint* endPoint;
|
||||
bool rc = false;
|
||||
|
||||
if(p_testState(ftp_passive) == false)
|
||||
{
|
||||
if(m_data != 0)
|
||||
{
|
||||
ep = m_data->Accept();
|
||||
if(ep != 0)
|
||||
{
|
||||
delete m_data;
|
||||
m_data = ep;
|
||||
if (_TestState(ftp_passive) == false) {
|
||||
if (fData != 0) {
|
||||
endPoint = fData->Accept();
|
||||
if (endPoint != 0) {
|
||||
delete fData;
|
||||
fData = endPoint;
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
rc = true;
|
||||
}
|
||||
else
|
||||
rc = true;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,54 +1,15 @@
|
||||
#include <string>
|
||||
#include <File.h>
|
||||
#ifndef FTP_CLIENT_H
|
||||
#define FTP_CLIENT_H
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include <File.h>
|
||||
#include <NetworkKit.h>
|
||||
|
||||
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.
|
||||
@@ -60,3 +21,54 @@ protected:
|
||||
#define WILL 251
|
||||
#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
|
||||
|
||||
@@ -1,80 +1,91 @@
|
||||
#include <Debug.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Settings.h"
|
||||
|
||||
Settings *settings = NULL;
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// generic setting handler classes
|
||||
#include <Debug.h>
|
||||
|
||||
|
||||
Settings* settings = NULL;
|
||||
|
||||
|
||||
StringValueSetting::StringValueSetting(const char* name, const char* defaultValue,
|
||||
const char* valueExpectedErrorString, const char* wrongValueErrorString)
|
||||
: SettingsArgvDispatcher(name),
|
||||
defaultValue(defaultValue),
|
||||
valueExpectedErrorString(valueExpectedErrorString),
|
||||
wrongValueErrorString(wrongValueErrorString),
|
||||
value(strdup(defaultValue))
|
||||
fDefaultValue(defaultValue),
|
||||
fValueExpectedErrorString(valueExpectedErrorString),
|
||||
fWrongValueErrorString(wrongValueErrorString),
|
||||
fValue(strdup(defaultValue))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
StringValueSetting::~StringValueSetting()
|
||||
{
|
||||
free(value);
|
||||
free(fValue);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringValueSetting::ValueChanged(const char* newValue)
|
||||
{
|
||||
if (newValue == value)
|
||||
if (newValue == fValue)
|
||||
// guard against self assingment
|
||||
return;
|
||||
|
||||
free(value);
|
||||
value = strdup(newValue);
|
||||
free(fValue);
|
||||
fValue = strdup(newValue);
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
StringValueSetting::Value() const
|
||||
{
|
||||
return value;
|
||||
return fValue;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringValueSetting::SaveSettingValue(Settings* settings)
|
||||
{
|
||||
printf("-------StringValueSetting::SaveSettingValue %s %s\n", Name(), value);
|
||||
settings->Write("\"%s\"", value);
|
||||
printf("-------StringValueSetting::SaveSettingValue %s %s\n", Name(), fValue);
|
||||
settings->Write("\"%s\"", fValue);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
StringValueSetting::NeedsSaving() const
|
||||
{
|
||||
// needs saving if different than default
|
||||
return strcmp(value, defaultValue) != 0;
|
||||
return strcmp(fValue, fDefaultValue) != 0;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
StringValueSetting::Handle(const char *const *argv)
|
||||
{
|
||||
if (!*++argv)
|
||||
return valueExpectedErrorString;
|
||||
return fValueExpectedErrorString;
|
||||
|
||||
ValueChanged(*argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
EnumeratedStringValueSetting::EnumeratedStringValueSetting(const char* name,
|
||||
const char *defaultValue, const char *const *values, const char *valueExpectedErrorString,
|
||||
const char* defaultValue, const char *const *values,
|
||||
const char* valueExpectedErrorString,
|
||||
const char* wrongValueErrorString)
|
||||
: StringValueSetting(name, defaultValue, valueExpectedErrorString, wrongValueErrorString),
|
||||
values(values)
|
||||
fValues(values)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
EnumeratedStringValueSetting::ValueChanged(const char* newValue)
|
||||
{
|
||||
@@ -82,9 +93,9 @@ EnumeratedStringValueSetting::ValueChanged(const char *newValue)
|
||||
// must be one of the enumerated values
|
||||
bool found = false;
|
||||
for (int32 index = 0; ; index++) {
|
||||
if (!values[index])
|
||||
if (!fValues[index])
|
||||
break;
|
||||
if (strcmp(values[index], newValue) != 0)
|
||||
if (strcmp(fValues[index], newValue) != 0)
|
||||
continue;
|
||||
found = true;
|
||||
break;
|
||||
@@ -94,120 +105,136 @@ EnumeratedStringValueSetting::ValueChanged(const char *newValue)
|
||||
StringValueSetting::ValueChanged(newValue);
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
EnumeratedStringValueSetting::Handle(const char *const *argv)
|
||||
{
|
||||
if (!*++argv)
|
||||
return valueExpectedErrorString;
|
||||
return fValueExpectedErrorString;
|
||||
|
||||
printf("-----EnumeratedStringValueSetting::Handle %s %s\n", *(argv-1), *argv);
|
||||
bool found = false;
|
||||
for (int32 index = 0; ; index++) {
|
||||
if (!values[index])
|
||||
if (!fValues[index])
|
||||
break;
|
||||
if (strcmp(values[index], *argv) != 0)
|
||||
if (strcmp(fValues[index], *argv) != 0)
|
||||
continue;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return wrongValueErrorString;
|
||||
return fWrongValueErrorString;
|
||||
|
||||
ValueChanged(*argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
ScalarValueSetting::ScalarValueSetting(const char* name, int32 defaultValue,
|
||||
const char* valueExpectedErrorString, const char* wrongValueErrorString,
|
||||
int32 min, int32 max)
|
||||
: SettingsArgvDispatcher(name),
|
||||
defaultValue(defaultValue),
|
||||
value(defaultValue),
|
||||
max(max),
|
||||
min(min),
|
||||
valueExpectedErrorString(valueExpectedErrorString),
|
||||
wrongValueErrorString(wrongValueErrorString)
|
||||
fDefaultValue(defaultValue),
|
||||
fValue(defaultValue),
|
||||
fMax(max),
|
||||
fMin(min),
|
||||
fValueExpectedErrorString(valueExpectedErrorString),
|
||||
fWrongValueErrorString(wrongValueErrorString)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScalarValueSetting::ValueChanged(int32 newValue)
|
||||
{
|
||||
ASSERT(newValue > min);
|
||||
ASSERT(newValue < max);
|
||||
value = newValue;
|
||||
ASSERT(newValue > fMin);
|
||||
ASSERT(newValue < fMax);
|
||||
fValue = newValue;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
ScalarValueSetting::Value() const
|
||||
{
|
||||
return value;
|
||||
return fValue;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScalarValueSetting::GetValueAsString(char* buffer) const
|
||||
{
|
||||
sprintf(buffer, "%ld", value);
|
||||
sprintf(buffer, "%ld", fValue);
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
ScalarValueSetting::Handle(const char *const *argv)
|
||||
{
|
||||
if (!*++argv)
|
||||
return valueExpectedErrorString;
|
||||
return fValueExpectedErrorString;
|
||||
|
||||
int32 newValue = atoi(*argv);
|
||||
if (newValue < min || newValue > max)
|
||||
return wrongValueErrorString;
|
||||
if (newValue < fMin || newValue > fMax)
|
||||
return fWrongValueErrorString;
|
||||
|
||||
value = newValue;
|
||||
fValue = newValue;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScalarValueSetting::SaveSettingValue(Settings* settings)
|
||||
{
|
||||
settings->Write("%d", value);
|
||||
settings->Write("%d", fValue);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ScalarValueSetting::NeedsSaving() const
|
||||
{
|
||||
return value != defaultValue;
|
||||
return fValue != fDefaultValue;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
BooleanValueSetting::BooleanValueSetting(const char* name, bool defaultValue)
|
||||
: ScalarValueSetting(name, defaultValue, 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BooleanValueSetting::Value() const
|
||||
{
|
||||
return value;
|
||||
return fValue;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
BooleanValueSetting::Handle(const char *const *argv)
|
||||
{
|
||||
if (!*++argv)
|
||||
return "or or off expected";
|
||||
return "on or off expected";
|
||||
|
||||
if (strcmp(*argv, "on") == 0)
|
||||
value = true;
|
||||
fValue = true;
|
||||
else if (strcmp(*argv, "off") == 0)
|
||||
value = false;
|
||||
fValue = false;
|
||||
else
|
||||
return "or or off expected";
|
||||
return "on or off expected";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BooleanValueSetting::SaveSettingValue(Settings* settings)
|
||||
{
|
||||
settings->Write(value ? "on" : "off");
|
||||
settings->Write(fValue ? "on" : "off");
|
||||
}
|
||||
|
||||
|
||||
+17
-15
@@ -1,5 +1,5 @@
|
||||
#ifndef __SETTINGS__
|
||||
#define __SETTINGS__
|
||||
#ifndef SETTINGS_H
|
||||
#define SETTINGS_H
|
||||
|
||||
#include "SettingsHandler.h"
|
||||
|
||||
@@ -23,12 +23,13 @@ protected:
|
||||
virtual void SaveSettingValue(Settings*);
|
||||
virtual bool NeedsSaving() const;
|
||||
|
||||
const char *defaultValue;
|
||||
const char *valueExpectedErrorString;
|
||||
const char *wrongValueErrorString;
|
||||
char *value;
|
||||
const char* fDefaultValue;
|
||||
const char* fValueExpectedErrorString;
|
||||
const char* fWrongValueErrorString;
|
||||
char* fValue;
|
||||
};
|
||||
|
||||
|
||||
class EnumeratedStringValueSetting : public StringValueSetting {
|
||||
// string setting, values that do not match string enumeration
|
||||
// are rejected
|
||||
@@ -41,10 +42,11 @@ public:
|
||||
virtual const char* Handle(const char *const *argv);
|
||||
|
||||
protected:
|
||||
const char *const *values;
|
||||
char *value;
|
||||
const char *const *fValues;
|
||||
char* fValue;
|
||||
};
|
||||
|
||||
|
||||
class ScalarValueSetting : public SettingsArgvDispatcher {
|
||||
// simple int32 setting
|
||||
public:
|
||||
@@ -61,12 +63,12 @@ protected:
|
||||
virtual void SaveSettingValue(Settings*);
|
||||
virtual bool NeedsSaving() const;
|
||||
|
||||
int32 defaultValue;
|
||||
int32 value;
|
||||
int32 max;
|
||||
int32 min;
|
||||
const char *valueExpectedErrorString;
|
||||
const char *wrongValueErrorString;
|
||||
int32 fDefaultValue;
|
||||
int32 fValue;
|
||||
int32 fMax;
|
||||
int32 fMin;
|
||||
const char* fValueExpectedErrorString;
|
||||
const char* fWrongValueErrorString;
|
||||
};
|
||||
|
||||
class BooleanValueSetting : public ScalarValueSetting {
|
||||
@@ -81,4 +83,4 @@ protected:
|
||||
virtual void SaveSettingValue(Settings *);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // SETTINGS_H
|
||||
|
||||
@@ -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"
|
||||
|
||||
ArgvParser::ArgvParser(const char *name)
|
||||
: file(0),
|
||||
buffer(0),
|
||||
pos(-1),
|
||||
argc(0),
|
||||
currentArgv(0),
|
||||
currentArgsPos(-1),
|
||||
sawBackslash(false),
|
||||
eatComment(false),
|
||||
inDoubleQuote(false),
|
||||
inSingleQuote(false),
|
||||
lineNo(0),
|
||||
fileName(name)
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Debug.h>
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <StopWatch.h>
|
||||
|
||||
|
||||
#if 0
|
||||
static int
|
||||
Compare(const SettingsArgvDispatcher* p1, const SettingsArgvDispatcher* p2)
|
||||
{
|
||||
file = fopen(fileName, "r");
|
||||
if (!file) {
|
||||
PRINT(("Error opening %s\n", fileName));
|
||||
return strcmp(p1->Name(), p2->Name());
|
||||
}
|
||||
#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;
|
||||
}
|
||||
buffer = new char [kBufferSize];
|
||||
currentArgv = new char * [1024];
|
||||
fBuffer = new char [kBufferSize];
|
||||
fCurrentArgv = new char* [1024];
|
||||
}
|
||||
|
||||
|
||||
ArgvParser::~ArgvParser()
|
||||
{
|
||||
delete [] buffer;
|
||||
delete[] fBuffer;
|
||||
|
||||
MakeArgvEmpty();
|
||||
delete [] currentArgv;
|
||||
delete [] fCurrentArgv;
|
||||
|
||||
if (file)
|
||||
fclose(file);
|
||||
if (fFile)
|
||||
fclose(fFile);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ArgvParser::MakeArgvEmpty()
|
||||
{
|
||||
// done with current argv, free it up
|
||||
for (int32 index = 0; index < argc; index++)
|
||||
delete currentArgv[index];
|
||||
for (int32 index = 0; index < fArgc; index++)
|
||||
delete fCurrentArgv[index];
|
||||
|
||||
argc = 0;
|
||||
fArgc = 0;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ArgvParser::SendArgv(ArgvHandler argvHandlerFunc, void* passThru)
|
||||
{
|
||||
if (argc) {
|
||||
if (fArgc) {
|
||||
NextArgv();
|
||||
currentArgv[argc] = 0;
|
||||
const char *result = (argvHandlerFunc)(argc, currentArgv, passThru);
|
||||
fCurrentArgv[fArgc] = 0;
|
||||
const char *result = (argvHandlerFunc)(fArgc, fCurrentArgv, passThru);
|
||||
if (result)
|
||||
printf("File %s; Line %ld # %s", fileName, lineNo, result);
|
||||
printf("File %s; Line %ld # %s", fFileName, fLineNo, result);
|
||||
MakeArgvEmpty();
|
||||
if (result)
|
||||
return B_ERROR;
|
||||
@@ -76,45 +104,49 @@ ArgvParser::SendArgv(ArgvHandler argvHandlerFunc, void *passThru)
|
||||
return B_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ArgvParser::NextArgv()
|
||||
{
|
||||
if (sawBackslash) {
|
||||
currentArgs[++currentArgsPos] = '\\';
|
||||
sawBackslash = false;
|
||||
if (fSawBackslash) {
|
||||
fCurrentArgs[++fCurrentArgsPos] = '\\';
|
||||
fSawBackslash = false;
|
||||
}
|
||||
currentArgs[++currentArgsPos] = '\0';
|
||||
fCurrentArgs[++fCurrentArgsPos] = '\0';
|
||||
// terminate current arg pos
|
||||
|
||||
// copy it as a string to the current argv slot
|
||||
currentArgv[argc] = new char [strlen(currentArgs) + 1];
|
||||
strcpy(currentArgv[argc], currentArgs);
|
||||
currentArgsPos = -1;
|
||||
argc++;
|
||||
fCurrentArgv[fArgc] = new char [strlen(fCurrentArgs) + 1];
|
||||
strcpy(fCurrentArgv[fArgc], fCurrentArgs);
|
||||
fCurrentArgsPos = -1;
|
||||
fArgc++;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ArgvParser::NextArgvIfNotEmpty()
|
||||
{
|
||||
if (!sawBackslash && currentArgsPos < 0)
|
||||
if (!fSawBackslash && fCurrentArgsPos < 0)
|
||||
return;
|
||||
|
||||
NextArgv();
|
||||
}
|
||||
|
||||
|
||||
char
|
||||
ArgvParser::GetCh()
|
||||
{
|
||||
if (pos < 0 || buffer[pos] == 0) {
|
||||
if (file == 0)
|
||||
if (fPos < 0 || fBuffer[fPos] == 0) {
|
||||
if (fFile == 0)
|
||||
return EOF;
|
||||
if (fgets(buffer, kBufferSize, file) == 0)
|
||||
if (fgets(fBuffer, kBufferSize, fFile) == 0)
|
||||
return EOF;
|
||||
pos = 0;
|
||||
fPos = 0;
|
||||
}
|
||||
return buffer[pos++];
|
||||
return fBuffer[fPos++];
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ArgvParser::EachArgv(const char* name, ArgvHandler argvHandlerFunc, void* passThru)
|
||||
{
|
||||
@@ -122,8 +154,10 @@ ArgvParser::EachArgv(const char *name, ArgvHandler argvHandlerFunc, void *passTh
|
||||
return parser.EachArgvPrivate(name, argvHandlerFunc, passThru);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ArgvParser::EachArgvPrivate(const char *name, ArgvHandler argvHandlerFunc, void *passThru)
|
||||
ArgvParser::EachArgvPrivate(const char* name, ArgvHandler argvHandlerFunc,
|
||||
void* passThru)
|
||||
{
|
||||
status_t result;
|
||||
|
||||
@@ -131,7 +165,7 @@ ArgvParser::EachArgvPrivate(const char *name, ArgvHandler argvHandlerFunc, void
|
||||
char ch = GetCh();
|
||||
if (ch == EOF) {
|
||||
// done with file
|
||||
if (inDoubleQuote || inSingleQuote) {
|
||||
if (fInDoubleQuote || fInSingleQuote) {
|
||||
printf("File %s # unterminated quote at end of file\n", name);
|
||||
result = B_ERROR;
|
||||
break;
|
||||
@@ -142,15 +176,15 @@ ArgvParser::EachArgvPrivate(const char *name, ArgvHandler argvHandlerFunc, void
|
||||
|
||||
if (ch == '\n' || ch == '\r') {
|
||||
// handle new line
|
||||
eatComment = false;
|
||||
if (!sawBackslash && (inDoubleQuote || inSingleQuote)) {
|
||||
printf("File %s ; Line %ld # unterminated quote\n", name, lineNo);
|
||||
fEatComment = false;
|
||||
if (!fSawBackslash && (fInDoubleQuote || fInSingleQuote)) {
|
||||
printf("File %s ; Line %ld # unterminated quote\n", name, fLineNo);
|
||||
result = B_ERROR;
|
||||
break;
|
||||
}
|
||||
lineNo++;
|
||||
if (sawBackslash) {
|
||||
sawBackslash = false;
|
||||
fLineNo++;
|
||||
if (fSawBackslash) {
|
||||
fSawBackslash = false;
|
||||
continue;
|
||||
}
|
||||
// end of line, flush all argv
|
||||
@@ -160,11 +194,11 @@ ArgvParser::EachArgvPrivate(const char *name, ArgvHandler argvHandlerFunc, void
|
||||
continue;
|
||||
}
|
||||
|
||||
if (eatComment)
|
||||
if (fEatComment)
|
||||
continue;
|
||||
|
||||
if (!sawBackslash) {
|
||||
if (!inDoubleQuote && !inSingleQuote) {
|
||||
if (!fSawBackslash) {
|
||||
if (!fInDoubleQuote && !fInSingleQuote) {
|
||||
if (ch == ';') {
|
||||
// semicolon is a command separator, pass on the whole argv
|
||||
result = SendArgv(argvHandlerFunc, passThru);
|
||||
@@ -173,45 +207,50 @@ ArgvParser::EachArgvPrivate(const char *name, ArgvHandler argvHandlerFunc, void
|
||||
continue;
|
||||
} else if (ch == '#') {
|
||||
// ignore everything on this line after this character
|
||||
eatComment = true;
|
||||
fEatComment = true;
|
||||
continue;
|
||||
} else if (ch == ' ' || ch == '\t') {
|
||||
// space or tab separates the individual arg strings
|
||||
NextArgvIfNotEmpty();
|
||||
continue;
|
||||
} else if (!sawBackslash && ch == '\\') {
|
||||
} else if (!fSawBackslash && ch == '\\') {
|
||||
// the next character is escaped
|
||||
sawBackslash = true;
|
||||
fSawBackslash = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!inSingleQuote && ch == '"') {
|
||||
if (!fInSingleQuote && ch == '"') {
|
||||
// enter/exit double quote handling
|
||||
inDoubleQuote = !inDoubleQuote;
|
||||
fInDoubleQuote = !fInDoubleQuote;
|
||||
continue;
|
||||
}
|
||||
if (!inDoubleQuote && ch == '\'') {
|
||||
if (!fInDoubleQuote && ch == '\'') {
|
||||
// enter/exit single quote handling
|
||||
inSingleQuote = !inSingleQuote;
|
||||
fInSingleQuote = !fInSingleQuote;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// we just pass through the escape sequence as is
|
||||
currentArgs[++currentArgsPos] = '\\';
|
||||
sawBackslash = false;
|
||||
fCurrentArgs[++fCurrentArgsPos] = '\\';
|
||||
fSawBackslash = false;
|
||||
}
|
||||
currentArgs[++currentArgsPos] = ch;
|
||||
fCurrentArgs[++fCurrentArgsPos] = ch;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
SettingsArgvDispatcher::SettingsArgvDispatcher(const char* name)
|
||||
: name(name)
|
||||
:
|
||||
fName(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsArgvDispatcher::SaveSettings(Settings* settings, bool onlyIfNonDefault)
|
||||
{
|
||||
@@ -222,6 +261,7 @@ SettingsArgvDispatcher::SaveSettings(Settings *settings, bool onlyIfNonDefault)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
SettingsArgvDispatcher::HandleRectValue(BRect &result, const char* const *argv,
|
||||
bool printError)
|
||||
@@ -253,6 +293,7 @@ SettingsArgvDispatcher::HandleRectValue(BRect &result, const char *const *argv,
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsArgvDispatcher::WriteRectValue(Settings* setting, BRect rect)
|
||||
{
|
||||
@@ -260,40 +301,43 @@ SettingsArgvDispatcher::WriteRectValue(Settings *setting, BRect rect)
|
||||
(int32)rect.right, (int32)rect.bottom);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int
|
||||
CompareByNameOne(const SettingsArgvDispatcher *item1, const SettingsArgvDispatcher *item2)
|
||||
{
|
||||
return strcmp(item1->Name(), item2->Name());
|
||||
}
|
||||
#endif
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
/*! \class Settings
|
||||
this class represents a list of all the settings handlers, reads and
|
||||
saves the settings file
|
||||
*/
|
||||
|
||||
|
||||
Settings::Settings(const char* filename, const char* settingsDirName)
|
||||
: fileName(filename),
|
||||
settingsDir(settingsDirName),
|
||||
list(0),
|
||||
count(0),
|
||||
listSize(30),
|
||||
currentSettings(0)
|
||||
:
|
||||
fFileName(filename),
|
||||
fSettingsDir(settingsDirName),
|
||||
fList(0),
|
||||
fCount(0),
|
||||
fListSize(30),
|
||||
fCurrentSettings(0)
|
||||
{
|
||||
#ifdef SINGLE_SETTING_FILE
|
||||
settingsHandler = this;
|
||||
#endif
|
||||
list = (SettingsArgvDispatcher **)calloc(listSize, sizeof(SettingsArgvDispatcher *));
|
||||
fList = (SettingsArgvDispatcher**)calloc(fListSize, sizeof(SettingsArgvDispatcher *));
|
||||
}
|
||||
|
||||
|
||||
Settings::~Settings()
|
||||
{
|
||||
for (int32 index = 0; index < count; index++)
|
||||
delete list[index];
|
||||
for (int32 index = 0; index < fCount; index++)
|
||||
delete fList[index];
|
||||
|
||||
free(list);
|
||||
free(fList);
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
Settings::ParseUserSettings(int, const char *const *argv, void *castToThis)
|
||||
Settings::_ParseUserSettings(int, const char* const *argv, void* castToThis)
|
||||
{
|
||||
if (!*argv)
|
||||
return 0;
|
||||
@@ -304,105 +348,108 @@ Settings::ParseUserSettings(int, const char *const *argv, void *castToThis)
|
||||
Settings* settings = (Settings*)castToThis;
|
||||
#endif
|
||||
|
||||
SettingsArgvDispatcher *handler = settings->Find(*argv);
|
||||
SettingsArgvDispatcher* handler = settings->_Find(*argv);
|
||||
if (!handler)
|
||||
return "unknown command";
|
||||
return handler->Handle(argv);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
static int
|
||||
Compare(const SettingsArgvDispatcher *p1, const SettingsArgvDispatcher *p2)
|
||||
{
|
||||
return strcmp(p1->Name(), p2->Name());
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
Returns false if argv dispatcher with the same name already
|
||||
registered
|
||||
*/
|
||||
bool
|
||||
Settings::Add(SettingsArgvDispatcher* setting)
|
||||
{
|
||||
// check for uniqueness
|
||||
if (Find(setting->Name()))
|
||||
if (_Find(setting->Name()))
|
||||
return false;
|
||||
|
||||
if (count >= listSize) {
|
||||
listSize += 30;
|
||||
list = (SettingsArgvDispatcher **)realloc(list,
|
||||
listSize * sizeof(SettingsArgvDispatcher *));
|
||||
if (fCount >= fListSize) {
|
||||
fListSize += 30;
|
||||
fList = (SettingsArgvDispatcher **)realloc(fList,
|
||||
fListSize * sizeof(SettingsArgvDispatcher *));
|
||||
}
|
||||
list[count++] = setting;
|
||||
fList[fCount++] = setting;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
SettingsArgvDispatcher*
|
||||
Settings::Find(const char *name)
|
||||
Settings::_Find(const char* name)
|
||||
{
|
||||
for (int32 index = 0; index < count; index++)
|
||||
if (strcmp(name, list[index]->Name()) == 0)
|
||||
return list[index];
|
||||
for (int32 index = 0; index < fCount; index++)
|
||||
if (strcmp(name, fList[index]->Name()) == 0)
|
||||
return fList[index];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::TryReadingSettings()
|
||||
{
|
||||
BPath prefsPath;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefsPath, true) == B_OK) {
|
||||
prefsPath.Append(settingsDir);
|
||||
prefsPath.Append(fSettingsDir);
|
||||
|
||||
BPath path(prefsPath);
|
||||
path.Append(fileName);
|
||||
ArgvParser::EachArgv(path.Path(), Settings::ParseUserSettings, this);
|
||||
path.Append(fFileName);
|
||||
ArgvParser::EachArgv(path.Path(), Settings::_ParseUserSettings, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::SaveSettings(bool onlyIfNonDefault)
|
||||
{
|
||||
ASSERT(SettingsHandler());
|
||||
SettingsHandler()->SaveCurrentSettings(onlyIfNonDefault);
|
||||
SettingsHandler()->_SaveCurrentSettings(onlyIfNonDefault);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::MakeSettingsDirectory(BDirectory *resultingSettingsDir)
|
||||
Settings::_MakeSettingsDirectory(BDirectory *resultingSettingsDir)
|
||||
{
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) != B_OK)
|
||||
return;
|
||||
|
||||
// make sure there is a directory
|
||||
path.Append(settingsDir);
|
||||
path.Append(fSettingsDir);
|
||||
mkdir(path.Path(), 0777);
|
||||
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;
|
||||
printf("+++++++++++ Settings::SaveCurrentSettings %s\n", fileName);
|
||||
|
||||
printf("+++++++++++ Settings::_SaveCurrentSettings %s\n", fFileName);
|
||||
// nuke old settings
|
||||
BEntry entry(&settingsDir, fileName);
|
||||
BEntry entry(&fSettingsDir, fFileName);
|
||||
entry.Remove();
|
||||
|
||||
BFile prefs(&entry, O_RDWR | O_CREAT);
|
||||
if (prefs.InitCheck() != B_OK)
|
||||
return;
|
||||
|
||||
currentSettings = &prefs;
|
||||
for (int32 index = 0; index < count; index++) {
|
||||
list[index]->SaveSettings(this, onlyIfNonDefault);
|
||||
fCurrentSettings = &prefs;
|
||||
for (int32 index = 0; index < fCount; index++) {
|
||||
fList[index]->SaveSettings(this, onlyIfNonDefault);
|
||||
}
|
||||
|
||||
currentSettings = 0;
|
||||
fCurrentSettings = 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::Write(const char* format, ...)
|
||||
{
|
||||
@@ -413,15 +460,17 @@ Settings::Write(const char *format, ...)
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::VSWrite(const char* format, va_list arg)
|
||||
{
|
||||
char buffer[2048];
|
||||
vsprintf(buffer, format, arg);
|
||||
ASSERT(currentSettings && currentSettings->InitCheck() == B_OK);
|
||||
currentSettings->Write(buffer, strlen(buffer));
|
||||
ASSERT(fCurrentSettings && fCurrentSettings->InitCheck() == B_OK);
|
||||
fCurrentSettings->Write(buffer, strlen(buffer));
|
||||
}
|
||||
|
||||
|
||||
#ifdef SINGLE_SETTING_FILE
|
||||
Settings* Settings::settingsHandler = 0;
|
||||
#endif
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#ifndef __SETTINGS_FILE__
|
||||
#define __SETTINGS_FILE__
|
||||
#ifndef SETTINGS_HANDLER_H
|
||||
#define SETTINGS_HANDLER_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
class BFile;
|
||||
class BDirectory;
|
||||
@@ -19,9 +22,8 @@ typedef const char *(*ArgvHandler)(int argc, const char *const *argv, void *para
|
||||
|
||||
const int32 kBufferSize = 1024;
|
||||
|
||||
|
||||
class ArgvParser {
|
||||
// this class opens a text file and passes the context in argv
|
||||
// format to a specified handler
|
||||
public:
|
||||
static status_t EachArgv(const char* name,
|
||||
ArgvHandler argvHandlerFunc, void* passThru);
|
||||
@@ -45,26 +47,27 @@ private:
|
||||
|
||||
void MakeArgvEmpty();
|
||||
|
||||
FILE *file;
|
||||
char *buffer;
|
||||
int32 pos;
|
||||
int32 numAvail;
|
||||
FILE* fFile;
|
||||
char* fBuffer;
|
||||
int32 fPos;
|
||||
int32 fNumAvail;
|
||||
|
||||
int argc;
|
||||
char **currentArgv;
|
||||
int fArgc;
|
||||
char** fCurrentArgv;
|
||||
|
||||
int32 currentArgsPos;
|
||||
char currentArgs [1024];
|
||||
int32 fCurrentArgsPos;
|
||||
char fCurrentArgs[1024];
|
||||
|
||||
bool sawBackslash;
|
||||
bool eatComment;
|
||||
bool inDoubleQuote;
|
||||
bool inSingleQuote;
|
||||
bool fSawBackslash;
|
||||
bool fEatComment;
|
||||
bool fInDoubleQuote;
|
||||
bool fInSingleQuote;
|
||||
|
||||
int32 lineNo;
|
||||
const char *fileName;
|
||||
int32 fLineNo;
|
||||
const char* fFileName;
|
||||
};
|
||||
|
||||
|
||||
class SettingsArgvDispatcher {
|
||||
// base class for a single setting item
|
||||
public:
|
||||
@@ -73,17 +76,18 @@ public:
|
||||
void SaveSettings(Settings* settings, bool onlyIfNonDefault);
|
||||
|
||||
const char* Name() const
|
||||
{ return name; }
|
||||
// name as it appears in the settings file
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
|
||||
virtual const char* Handle(const char* const *argv) = 0;
|
||||
// override this adding an argv parser that reads in the
|
||||
// values in argv format for this setting
|
||||
// return a pointer to an error message or null if parsed OK
|
||||
|
||||
bool HandleRectValue(BRect&, const char* const *argv,
|
||||
bool printError = true);
|
||||
|
||||
// some handy reader/writer calls
|
||||
bool HandleRectValue(BRect &, const char *const *argv, bool printError = true);
|
||||
// static bool HandleColorValue(rgb_color &, const char *const *argv, bool printError = true);
|
||||
void WriteRectValue(Settings*, BRect);
|
||||
// void WriteColorValue(BRect);
|
||||
@@ -94,16 +98,17 @@ protected:
|
||||
// text format
|
||||
|
||||
virtual bool NeedsSaving() const
|
||||
{ return true; }
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// override to return false if current value is equal to the default
|
||||
// and does not need saving
|
||||
private:
|
||||
const char *name;
|
||||
const char* fName;
|
||||
};
|
||||
|
||||
|
||||
class Settings {
|
||||
// this class is a list of all the settings handlers, reads and
|
||||
// saves the settings file
|
||||
public:
|
||||
Settings(const char* filename, const char* settingsDirName);
|
||||
~Settings();
|
||||
@@ -112,15 +117,17 @@ public:
|
||||
|
||||
#ifdef SINGLE_SETTING_FILE
|
||||
static Settings* SettingsHandler()
|
||||
{ return settingsHandler; }
|
||||
{
|
||||
return settingsHandler;
|
||||
}
|
||||
#else
|
||||
Settings* SettingsHandler()
|
||||
{ return this; }
|
||||
{
|
||||
return this;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Add(SettingsArgvDispatcher *);
|
||||
// return false if argv dispatcher with the same name already
|
||||
// registered
|
||||
|
||||
void Write(const char* format, ...);
|
||||
void VSWrite(const char*, va_list);
|
||||
@@ -130,19 +137,18 @@ public:
|
||||
#endif
|
||||
|
||||
private:
|
||||
void MakeSettingsDirectory(BDirectory *);
|
||||
void _MakeSettingsDirectory(BDirectory*);
|
||||
|
||||
SettingsArgvDispatcher *Find(const char *);
|
||||
static const char *ParseUserSettings(int, const char *const *argv, void *);
|
||||
void SaveCurrentSettings(bool onlyIfNonDefault);
|
||||
SettingsArgvDispatcher* _Find(const char*);
|
||||
static const char* _ParseUserSettings(int, const char *const *argv, void*);
|
||||
void _SaveCurrentSettings(bool onlyIfNonDefault);
|
||||
|
||||
const char *fileName;
|
||||
const char *settingsDir;
|
||||
SettingsArgvDispatcher **list;
|
||||
int32 count;
|
||||
int32 listSize;
|
||||
BFile *currentSettings;
|
||||
const char* fFileName;
|
||||
const char* fSettingsDir;
|
||||
SettingsArgvDispatcher** fList;
|
||||
int32 fCount;
|
||||
int32 fListSize;
|
||||
BFile* fCurrentSettings;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
#endif // SETTINGS_HANDLER_H
|
||||
|
||||
+268
-329
File diff suppressed because it is too large
Load Diff
@@ -1,21 +1,21 @@
|
||||
// Copyright (c) 1998-99, Be Incorporated, All Rights Reserved.
|
||||
// SMS
|
||||
/* 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 <Window.h>
|
||||
#include <MediaNode.h>
|
||||
#include <TranslationKit.h>
|
||||
#include <BufferConsumer.h>
|
||||
#include <TimedEventQueue.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;
|
||||
bigtime_t rate;
|
||||
uint32 imageFormat;
|
||||
@@ -30,147 +30,119 @@ typedef struct
|
||||
|
||||
#define FTP_INFO 0x60000001
|
||||
|
||||
class VideoConsumer :
|
||||
public BMediaEventLooper,
|
||||
public BBufferConsumer
|
||||
{
|
||||
class BStringView;
|
||||
|
||||
|
||||
|
||||
class VideoConsumer : public BMediaEventLooper, public BBufferConsumer {
|
||||
public:
|
||||
VideoConsumer(
|
||||
const char * name,
|
||||
BView * view,
|
||||
BStringView * statusLine,
|
||||
BMediaAddOn *addon,
|
||||
const uint32 internal_id);
|
||||
VideoConsumer(const char* name, BView* view, BStringView* statusLine,
|
||||
BMediaAddOn *addon, const uint32 internalId);
|
||||
~VideoConsumer();
|
||||
|
||||
/* BMediaNode */
|
||||
public:
|
||||
|
||||
virtual BMediaAddOn* AddOn(long* cookie) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void Start(bigtime_t performance_time);
|
||||
virtual void Stop(bigtime_t performance_time, bool immediate);
|
||||
virtual void Seek(bigtime_t media_time, bigtime_t performance_time);
|
||||
virtual void TimeWarp(bigtime_t at_real_time, bigtime_t to_performance_time);
|
||||
virtual void Start(bigtime_t performanceTime);
|
||||
virtual void Stop(bigtime_t performanceTime, bool immediate);
|
||||
virtual void Seek(bigtime_t mediaTime, bigtime_t performanceTime);
|
||||
virtual void TimeWarp(bigtime_t atRealTime,
|
||||
bigtime_t toPerformanceTime);
|
||||
|
||||
virtual void NodeRegistered();
|
||||
virtual status_t RequestCompleted(
|
||||
const media_request_info & info);
|
||||
virtual status_t RequestCompleted(const media_request_info& info);
|
||||
|
||||
virtual status_t HandleMessage(
|
||||
int32 message,
|
||||
const void * data,
|
||||
virtual status_t HandleMessage(int32 message, const void* data,
|
||||
size_t size);
|
||||
|
||||
virtual status_t DeleteHook(BMediaNode* node);
|
||||
|
||||
/* BMediaEventLooper */
|
||||
protected:
|
||||
virtual void HandleEvent(
|
||||
const media_timed_event *event,
|
||||
bigtime_t lateness,
|
||||
bool realTimeEvent);
|
||||
virtual void HandleEvent(const media_timed_event* event,
|
||||
bigtime_t lateness, bool realTimeEvent);
|
||||
|
||||
/* BBufferConsumer */
|
||||
public:
|
||||
|
||||
virtual status_t AcceptFormat(
|
||||
const media_destination &dest,
|
||||
virtual status_t AcceptFormat(const media_destination& dest,
|
||||
media_format* format);
|
||||
virtual status_t GetNextInput(
|
||||
int32 * cookie,
|
||||
media_input * out_input);
|
||||
|
||||
virtual void DisposeInputCookie(
|
||||
int32 cookie);
|
||||
virtual status_t GetNextInput(int32* cookie, media_input* outInput);
|
||||
|
||||
virtual void DisposeInputCookie(int32 cookie);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void BufferReceived(
|
||||
BBuffer * buffer);
|
||||
virtual void BufferReceived(BBuffer* buffer);
|
||||
|
||||
private:
|
||||
virtual void ProducerDataStatus(const media_destination &forWhom,
|
||||
int32 status, bigtime_t atMediaTime);
|
||||
|
||||
virtual void ProducerDataStatus(
|
||||
const media_destination &for_whom,
|
||||
int32 status,
|
||||
bigtime_t at_media_time);
|
||||
virtual status_t GetLatencyFor(
|
||||
const media_destination &for_whom,
|
||||
bigtime_t * out_latency,
|
||||
media_node_id * out_id);
|
||||
virtual status_t Connected(
|
||||
const media_source &producer,
|
||||
const media_destination &where,
|
||||
const media_format & with_format,
|
||||
media_input * out_input);
|
||||
virtual void Disconnected(
|
||||
const media_source &producer,
|
||||
virtual status_t GetLatencyFor(const media_destination& forWhom,
|
||||
bigtime_t* outLatency, media_node_id* outId);
|
||||
|
||||
virtual status_t Connected(const media_source& producer,
|
||||
const media_destination& where, const media_format& withFormat,
|
||||
media_input* outInput);
|
||||
|
||||
virtual void Disconnected(const media_source& producer,
|
||||
const media_destination& where);
|
||||
virtual status_t FormatChanged(
|
||||
const media_source & producer,
|
||||
const media_destination & consumer,
|
||||
int32 from_change_count,
|
||||
|
||||
virtual status_t FormatChanged(const media_source& producer,
|
||||
const media_destination& consumer, int32 fromChangeCount,
|
||||
const media_format& format);
|
||||
|
||||
/* implementation */
|
||||
|
||||
public:
|
||||
status_t CreateBuffers(
|
||||
const media_format & with_format);
|
||||
status_t CreateBuffers(const media_format& withFormat);
|
||||
|
||||
void DeleteBuffers();
|
||||
|
||||
static status_t FtpRun(
|
||||
void *data);
|
||||
static status_t FtpRun(void* data);
|
||||
|
||||
void FtpThread(
|
||||
void);
|
||||
void FtpThread();
|
||||
|
||||
void UpdateFtpStatus(
|
||||
char *status);
|
||||
void UpdateFtpStatus(char* status);
|
||||
|
||||
status_t LocalSave(
|
||||
char *filename,
|
||||
BBitmap *bitmap);
|
||||
status_t LocalSave(char* filename, BBitmap* bitmap);
|
||||
|
||||
status_t FtpSave(
|
||||
char *filename);
|
||||
status_t FtpSave(char* filename);
|
||||
|
||||
private:
|
||||
BStringView* fStatusLine;
|
||||
uint32 fInternalID;
|
||||
BMediaAddOn* fAddOn;
|
||||
|
||||
BStringView * mStatusLine;
|
||||
uint32 mInternalID;
|
||||
BMediaAddOn *mAddOn;
|
||||
thread_id fFtpThread;
|
||||
|
||||
thread_id mFtpThread;
|
||||
bool fConnectionActive;
|
||||
media_input fIn;
|
||||
media_destination fDestination;
|
||||
bigtime_t fMyLatency;
|
||||
|
||||
bool mConnectionActive;
|
||||
media_input mIn;
|
||||
media_destination mDestination;
|
||||
bigtime_t mMyLatency;
|
||||
BWindow* fWindow;
|
||||
BView* fView;
|
||||
BBitmap* fBitmap[3];
|
||||
bool fOurBuffers;
|
||||
BBufferGroup* fBuffers;
|
||||
uint32 fBufferMap[3];
|
||||
|
||||
BWindow *mWindow;
|
||||
BView *mView;
|
||||
BBitmap *mBitmap[3];
|
||||
bool mOurBuffers;
|
||||
BBufferGroup *mBuffers;
|
||||
uint32 mBufferMap[3];
|
||||
BBitmap* fFtpBitmap;
|
||||
volatile bool fTimeToFtp;
|
||||
volatile bool fFtpComplete;
|
||||
|
||||
BBitmap *mFtpBitmap;
|
||||
volatile bool mTimeToFtp;
|
||||
volatile bool mFtpComplete;
|
||||
|
||||
bigtime_t mRate;
|
||||
uint32 mImageFormat;
|
||||
int32 mTranslator;
|
||||
bool mPassiveFtp;
|
||||
char mFileNameText[64];
|
||||
char mServerText[64];
|
||||
char mLoginText[64];
|
||||
char mPasswordText[64];
|
||||
char mDirectoryText[64];
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user