Register/UnregisterInterface() are now private.

Moved report code into its own class.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4106 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Waldemar Kornewald
2003-07-27 10:03:36 +00:00
parent e59c7b66ea
commit d7344480f1
6 changed files with 198 additions and 166 deletions
+9 -11
View File
@@ -7,7 +7,7 @@
#include "KPPPStateMachine.h" #include "KPPPStateMachine.h"
#include "KPPPLCP.h" #include "KPPPLCP.h"
#include "KPPPReport.h" #include "KPPPReportManager.h"
#include "List.h" #include "List.h"
#include "LockerHelper.h" #include "LockerHelper.h"
@@ -40,10 +40,6 @@ class PPPInterface {
PPPLCP& LCP() const PPPLCP& LCP() const
{ return fLCP; } { return fLCP; }
bool RegisterInterface();
// adds us to the manager module and
// saves the returned ifnet structure
bool UnregisterInterface();
ifnet *Ifnet() const ifnet *Ifnet() const
{ return fIfnet; } { return fIfnet; }
@@ -105,11 +101,8 @@ class PPPInterface {
bool Down(); bool Down();
bool IsUp() const; bool IsUp() const;
void EnableReports(PPP_REPORT_TYPE type, thread_id thread, bool Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 length)
int32 flags = PPP_NO_REPORT_FLAGS); { fReportManager.Report(type, code, data, length); }
void DisableReports(PPP_REPORT_TYPE type, thread_id thread);
bool DoesReport(PPP_REPORT_TYPE type, thread_id thread);
bool Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 length);
// returns false if reply was bad (or an error occured) // returns false if reply was bad (or an error occured)
bool LoadModules(const driver_settings *settings, bool LoadModules(const driver_settings *settings,
@@ -126,6 +119,11 @@ class PPPInterface {
// SendToDevice()! // SendToDevice()!
private: private:
bool RegisterInterface();
// adds us to the manager module and
// saves the returned ifnet structure
bool UnregisterInterface();
void CalculateMRU(); void CalculateMRU();
// multilink methods // multilink methods
@@ -136,6 +134,7 @@ class PPPInterface {
driver_parameter *fSettings; driver_parameter *fSettings;
PPPStateMachine fStateMachine; PPPStateMachine fStateMachine;
PPPLCP fLCP; PPPLCP fLCP;
PPPReportManager fReportManager;
ifnet *fIfnet; ifnet *fIfnet;
ppp_manager_info *fManager; ppp_manager_info *fManager;
@@ -156,7 +155,6 @@ class PPPInterface {
PPPEncapsulator *fFirstEncapsulator; PPPEncapsulator *fFirstEncapsulator;
List<PPPProtocol*> fProtocols; List<PPPProtocol*> fProtocols;
List<ppp_module_info*> fModules; List<ppp_module_info*> fModules;
List<ppp_report_request> fReportRequests;
BLocker& fLock; BLocker& fLock;
}; };
@@ -1,5 +1,5 @@
#ifndef _K_PPP_REPORT__H #ifndef _K_PPP_REPORT_DEFS__H
#define _K_PPP_REPORT__H #define _K_PPP_REPORT_DEFS__H
#define PPP_REPORT_DATA_LIMIT 128 #define PPP_REPORT_DATA_LIMIT 128
// how much optional data can be added to the report // how much optional data can be added to the report
@@ -0,0 +1,27 @@
#ifndef _K_PPP_REPORT_MANAGER__H
#define _K_PPP_REPORT_MANAGER__H
#include "KPPPReportDefs.h"
#include "List.h"
#include "LockerHelper.h"
class PPPReportManager {
public:
PPPReportManager(BLocker& lock);
void EnableReports(PPP_REPORT_TYPE type, thread_id thread,
int32 flags = PPP_NO_REPORT_FLAGS);
void DisableReports(PPP_REPORT_TYPE type, thread_id thread);
bool DoesReport(PPP_REPORT_TYPE type, thread_id thread);
bool Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 length);
// returns false if reply was bad (or an error occured)
private:
BLocker& fLock;
List<ppp_report_request> fReportRequests;
};
#endif
+51 -152
View File
@@ -25,9 +25,9 @@
PPPInterface::PPPInterface(driver_settings *settings, PPPInterface *parent = NULL) PPPInterface::PPPInterface(driver_settings *settings, PPPInterface *parent = NULL)
: fSettings(dup_driver_settings(settings)), : fSettings(dup_driver_settings(settings)),
StateMachine(*this), LCP(*this), fIfnet(NULL), fLinkMTU(1500), fStateMachine(*this), fLCP(*this), fReportManager(StateMachine().Locker()),
fAccessing(0), fChildrenCount(0), fDevice(NULL), fFirstEncapsulator(NULL), fIfnet(NULL), fLinkMTU(1500), fAccessing(0), fChildrenCount(0),
fLock(StateMachine().Locker()) fDevice(NULL), fFirstEncapsulator(NULL), fLock(StateMachine().Locker())
{ {
if(get_module(PPP_MANAGER_MODULE_NAME, (module_info**) &fManager) != B_OK) if(get_module(PPP_MANAGER_MODULE_NAME, (module_info**) &fManager) != B_OK)
fManager = NULL; fManager = NULL;
@@ -119,54 +119,6 @@ PPPInterface::InitCheck() const
} }
bool
PPPInterface::RegisterInterface()
{
if(fIfnet)
return true;
// we are already registered
if(!InitCheck())
return false;
// we cannot register if something is wrong
// only MainInterfaces get an ifnet
if(IsMultilink() && Parent() && Parent()->RegisterInterface())
return true;
if(!fManager)
return false;
fIfnet = fManager->add_interface(this);
if(!fIfnet)
return false;
return true;
}
bool
PPPInterface::UnregisterInterface()
{
if(!fIfnet)
return true;
// we are already unregistered
// only MainInterfaces get an ifnet
if(IsMultilink() && Parent())
return true;
if(!fManager)
return false;
fManager->remove_interface(this);
fIfnet = NULL;
return true;
}
void void
PPPInterface::SetLinkMTU(uint32 linkMTU) PPPInterface::SetLinkMTU(uint32 linkMTU)
{ {
@@ -509,107 +461,6 @@ PPPInterface::IsUp() const
} }
void
PPPInterface::EnableReports(PPP_REPORT_TYPE type, thread_id thread,
int32 flags = PPP_NO_REPORT_FLAGS)
{
LockerHelper locker(fLock);
ppp_report_request request;
request.type = type;
request.thread = thread;
request.flags = flags;
fReportRequests.AddItem(request);
}
void
PPPInterface::DisableReports(PPP_REPORT_TYPE type, thread_id thread)
{
LockerHelper locker(fLock);
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
ppp_report_request& request = fReportRequests.ItemAt(i);
if(request.thread != thread)
continue;
if(report.type == type)
fReportRequest.RemoveItem(request);
}
}
bool
PPPInterface::DoesReport(PPP_REPORT_TYPE type, thread_id thread)
{
LockerHelper locker(fLock);
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
ppp_report_request& request = fReportRequests.ItemAt(i);
if(request.thread == thread && request.type == type)
return true;
}
return false;
}
bool
PPPInterface::Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 length)
{
if(length > PPP_REPORT_DATA_LIMIT)
return false;
if(fReportRequests.CountItems() == 0)
return true;
if(!data)
length = 0;
LockerHelper locker(fLock);
int32 code, query, result;
thread_id sender;
bool acceptable = true;
report_packet report;
report.type = type;
report.code = code;
report.length = length;
memcpy(report.data, data, length);
for(int32 index = 0; index < fReportRequests.CountItems(); index++) {
ppp_report_request& request = fReportRequests.ItemAt(index);
result = send_data_with_timeout(request.port, PPP_REPORT_CODE, &report,
sizeof(report), PPP_REPORT_TIMEOUT);
if(result == B_BAD_THREAD_ID || result == B_NO_MEMORY) {
fReportRequests.RemoveItem(request);
--index;
continue;
} else if(result == B_OK) {
if(request.flags & PPP_WAIT_FOR_REPLY) {
result = receive_data_with_timeout(fPort, &code, NULL, 0,
PPP_REPORT_TIMEOUT);
if(result == B_OK && code != B_OK)
successful = false;
}
}
if(request.flags & PPP_REMOVE_AFTER_REPORT) {
fReportRequests.RemoveItem(request);
--index;
}
}
return acceptable;
}
bool bool
PPPInterface::LoadModules(const driver_settings *settings, PPPInterface::LoadModules(const driver_settings *settings,
int32 start, int32 count) int32 start, int32 count)
@@ -927,6 +778,54 @@ PPPInterface::ReceiveFromDevice(mbuf *packet)
} }
bool
PPPInterface::RegisterInterface()
{
if(fIfnet)
return true;
// we are already registered
if(!InitCheck())
return false;
// we cannot register if something is wrong
// only MainInterfaces get an ifnet
if(IsMultilink() && Parent() && Parent()->RegisterInterface())
return true;
if(!fManager)
return false;
fIfnet = fManager->add_interface(this);
if(!fIfnet)
return false;
return true;
}
bool
PPPInterface::UnregisterInterface()
{
if(!fIfnet)
return true;
// we are already unregistered
// only MainInterfaces get an ifnet
if(IsMultilink() && Parent())
return true;
if(!fManager)
return false;
fManager->remove_interface(this);
fIfnet = NULL;
return true;
}
void void
PPPInterface::CalculateMRU() PPPInterface::CalculateMRU()
{ {
@@ -0,0 +1,108 @@
#include "KPPPReportManager.h"
PPPReportManager::PPPReportManager(BLocker& lock)
: fLock(lock)
{
}
void
PPPReportManager::EnableReports(PPP_REPORT_TYPE type, thread_id thread,
int32 flags = PPP_NO_REPORT_FLAGS)
{
LockerHelper locker(fLock);
ppp_report_request request;
request.type = type;
request.thread = thread;
request.flags = flags;
fReportRequests.AddItem(request);
}
void
PPPReportManager::DisableReports(PPP_REPORT_TYPE type, thread_id thread)
{
LockerHelper locker(fLock);
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
ppp_report_request& request = fReportRequests.ItemAt(i);
if(request.thread != thread)
continue;
if(report.type == type)
fReportRequest.RemoveItem(request);
}
}
bool
PPPReportManager::DoesReport(PPP_REPORT_TYPE type, thread_id thread)
{
LockerHelper locker(fLock);
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
ppp_report_request& request = fReportRequests.ItemAt(i);
if(request.thread == thread && request.type == type)
return true;
}
return false;
}
bool
PPPReportManager::Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 length)
{
if(length > PPP_REPORT_DATA_LIMIT)
return false;
if(fReportRequests.CountItems() == 0)
return true;
if(!data)
length = 0;
LockerHelper locker(fLock);
int32 code, query, result;
thread_id sender;
bool acceptable = true;
report_packet report;
report.type = type;
report.code = code;
report.length = length;
memcpy(report.data, data, length);
for(int32 index = 0; index < fReportRequests.CountItems(); index++) {
ppp_report_request& request = fReportRequests.ItemAt(index);
result = send_data_with_timeout(request.port, PPP_REPORT_CODE, &report,
sizeof(report), PPP_REPORT_TIMEOUT);
if(result == B_BAD_THREAD_ID || result == B_NO_MEMORY) {
fReportRequests.RemoveItem(request);
--index;
continue;
} else if(result == B_OK) {
if(request.flags & PPP_WAIT_FOR_REPLY) {
result = receive_data_with_timeout(fPort, &code, NULL, 0,
PPP_REPORT_TIMEOUT);
if(result == B_OK && code != B_OK)
successful = false;
}
}
if(request.flags & PPP_REMOVE_AFTER_REPORT) {
fReportRequests.RemoveItem(request);
--index;
}
}
return acceptable;
}
@@ -624,9 +624,9 @@ PPPStateMachine::RCRGoodEvent(mbuf *packet)
NewPhase(PPP_ESTABLISHMENT_PHASE); NewPhase(PPP_ESTABLISHMENT_PHASE);
// tell handlers that we are reconfiguring // tell handlers that we are reconfiguring
locker.UnlockNow(); locker.UnlockNow();
ThisLayerDown();
SendConfigureRequest(); SendConfigureRequest();
SendConfigureAck(packet); SendConfigureAck(packet);
ThisLayerDown();
break; break;
} }
} }