自己备份的代码

FM的代码,自己mark下

 

///
//  System           : WIBRO
//  Subsystem        : OAM
//  Process          : FM
//  Class            : AaaStateManager
//  File             : AaaStateManager.cpp
//  Description      :
//  See Also         : AaaStateManager.h
//  Author           : cleartool lshist AaaStateManager.cpp
//  Created          : cleartool lshist AaaStateManager.cpp
//  Revision History : cleartool lshist AaaStateManager.cpp
///

#if defined(__MIPS__) || defined(__ARM__) || defined(__PPC85XX__)|| defined(__x86__)||defined(_OAM_BLADE_)
#include <cstdio>
#include <cstring>
#include <string>
#include "msg_id_oam.h"
#include "cpsofm_msg.h"
#include "mbox_id_oam.h"
#include "mbox_id_cps.h"
#include "conf_def.h"
#include "cp_rel.h"
#include "wibro_ras_rel.h"
#include "em_interface.h"
#include "ofm_def.h"
#include "BoardCode.h"
#include "BoardConf.h"
#include "DateTime.h"
#include "Debug.h"
#include "EnumUtil.h"
#include "EventManager.h"
#include "AaaStateManager.h"
#include "PldRelation.h"
#include "SelfConf.h"
#include "StringUtil.h"
#include "SystemConf.h"
#include "GmsClient.h"
#include "TrapManager.h"
#include "IpcClient.h"
#include "MwUtil.h"
#include "SelfConf.h"
#include "AlarmGroup.h"
namespace fm
{
using namespace std;
struct AaaAlarmMapItem
{
 word16 alarm;
 char sub[128];
};

///
// AaaStateManager class members

int AaaStateManager::cid = StringUtil::hashCode("AaaStateManager");
AaaStateManager* AaaStateManager::instance = NULL;


AaaStateManager::AaaStateManager()
: SnmpCommandHandlerBase(sizeof(AaaStateInfo), _msg_ReqUsiAaaState_BsmOfm, _msg_RspUsiAaaState_OfmBsm)
{
 SnmpCommandHandlerBase::req[_msg_ReqUsiAaaState_BsmOfm] = "sts-Aaa ";

 // Initialize SNMP table.
 AaaStateInfo v;

 table.keys.add(SnmpColumn(&v, &v.AaaId));

 // Initialize SNMP table row helper.
 table.rows.helper(SnmpRowHelper(&Provider::valid, &Provider::eval, &Provider::get));

 // Initialize SNMP table row.
 Provider::table = &table;

 // Subscribe event delegate.                                                                  
         _evt.delegate(EID_FM_INIT_COMPLETED,                                                          
                 EventDelegate(this, &AaaStateManager::onInitCompleted));               
 // Subscribe event delegate.
 _chn.delegate( _msg_NotiAaaState_UsiOfm, ChannelDelegate(this, &AaaStateManager::onAaaStateChanged));

 // Register console command.
 instance = this;
 for (word32 i = 0; i < FM_MAX_AAA_COUNT; i++)
 {
  ude[i].set(i);
 }
 
 dusRegisterCmd("simAaareport", 9, onCommand2, "sim Aaa state");
 dusRegisterCmd("disAaasts", 9, onCommand, "Display Aaa state");
}

AaaStateManager::~AaaStateManager()
{
 instance = NULL;

 Provider::table = NULL;
}
void AaaStateManager::onInitCompleted(void* params)                          
{
 notiCpsOfmInfo();
                                                                        
}              

void AaaStateManager::onAaaStateChanged(IChannelClient& client)
{
 if (client.receiveBuffer() == NULL)
 {
  Debug::print(cid, "ex: invalid; CallFaultTrapNotifier:_msg_FaultReport_AscOfm/n");
  return;
 }


//send Trap  
 AaaStateInfo noti = {0,};

 AaaStateReport_UsiOfm_Type revData ={0,};
 memcpy(&revData, client.receiveBuffer(),
  min(client.messageLength(), sizeof(AaaStateReport_UsiOfm_Type)));
 DateTime::fill(noti.AaacTimestamp, 11, DateTime::now());
    
 int AaaIdx = Read16(revData.AaaId);
 ude[AaaIdx].pre_state = ude[AaaIdx].val.AaaState;
 
 ude[AaaIdx].val.AaaId = AaaIdx;
 noti.AaaId = AaaIdx;
 ude[AaaIdx].val.AaaIpVer = Read32(revData.AaaIp.IpVer);
        noti.AaaIpVer = Read32(revData.AaaIp.IpVer);
 if( noti.AaaIpVer == IPV4)
        { 
  ude[AaaIdx].val.AaaIpV4   =Read32(revData.AaaIp.Ip.V4);
  noti.AaaIpV4 = Read32(revData.AaaIp.Ip.V4);
        }
 else
 {
             for(int n = 0 ; n < 16 ; n++)
  {
                 ude[AaaIdx].val.AaaIpV6[n] = revData.AaaIp.Ip.V6[n];
   noti.AaaIpV6[n] = revData.AaaIp.Ip.V6[n];
  }
 }
 ude[AaaIdx].val.AaaState = Read8(revData.AaaState);
 noti.AaaState = Read8(revData.AaaState);
 memcpy(&(ude[AaaIdx].val.ReleaseReasonStr), &(revData.ReleaseReasonStr),sizeof(revData.ReleaseReasonStr));
 memcpy(&(noti.ReleaseReasonStr), &(revData.ReleaseReasonStr),sizeof(revData.ReleaseReasonStr));
 memcpy(&(ude[AaaIdx].val.AaacTimestamp), &(noti.AaacTimestamp),sizeof(noti.AaacTimestamp));
 Provider* pv = find(AaaIdx);
 if(NULL != pv)
 { 
         pv->val.AaaId = AaaIdx;
         pv->val.AaaIpVer = noti.AaaIpVer;
         if( pv->val.AaaIpVer == IPV4)
                {
                        pv->val.AaaIpV4   =noti.AaaIpV4;
                }
                else
                {
                        for(int n = 0 ; n < 16 ; n++)
                        {
                                pv->val.AaaIpV6[n] = noti.AaaIpV6[n];
                        }
                }
  pv->val.AaaState = Read8(noti.AaaState);
 
         memcpy(&(pv->val.ReleaseReasonStr), &(noti.ReleaseReasonStr),sizeof(noti.ReleaseReasonStr));
         memcpy(&(pv->val.AaacTimestamp), &(noti.AaacTimestamp),sizeof(noti.AaacTimestamp));
  pv->sndStat(); 
 }

}

AaaStateManager::Provider* AaaStateManager::find(word16 AaaId)
{
 for (word32 i = 0; i < FM_MAX_AAA_COUNT; i++)
 {
  
  bool match = (ude[i].val.AaaId == AaaId);
  if (match)
  {
   return &ude[i];
  }

 }
 return NULL;
}
void AaaStateManager::display()
{
 for (word32 i = 0; i < table.rows.count(); i++)
 {
  Provider* p = (Provider*)table.rows[i];

  if (p == NULL)
  {
   continue;
  }

  if (!p->valid())
  {
   continue;
  }

  p->eval();

  AaaStateInfo* val = (AaaStateInfo*)p->get();

  if (val == NULL)
  {
   continue;
  }

  char sid[32] = {0,};

  if (val->AaaId != 0xFFFF)
  {
   snprintf(sid, 31, "Aaa-%02d", val->AaaId);
  }
  else
  {
   snprintf(sid, 31, "Aaa-**-**");
  }

  dusPrint("fm", PL_CMD, "%s-%d /n",
    sid,val->AaaState);
 }
}

int AaaStateManager::onCommand(int argc, char** argv)
{
 try
 {
  if (instance != NULL)
  {
   instance->display();
  }

  dusPrint("fm", PL_CMD, "ok/n");
 }
 catch (exception& ex)
 {
  dusPrint("fm", PL_CMD, "ex: %s/n", ex.what());
 }
 catch (...)
 {
  dusPrint("fm", PL_CMD, "ex: unknown/n");
 }

 return 0;
}
int AaaStateManager::onCommand2(int argc, char** argv)
{

 int choice = atoi(argv[1]);

 try
        {
                if (instance != NULL)
                {
   AaaStateReport_UsiOfm_Type noti_msg;
   memset(&noti_msg.MsgHdr, 0, sizeof(MsgHeader_Type));
   noti_msg.MsgHdr.msg_id = Write16(_msg_NotiAaaState_UsiOfm);
   noti_msg.AaaId = Write16(choice);
   noti_msg.AaaIp.IpVer = Write32(4);
                 if( Read32(noti_msg.AaaIp.IpVer) == IPV4)
                 {
                         noti_msg.AaaIp.Ip.V4  =Write32(1835600026);
                 }
                 noti_msg.AaaState = atoi(argv[2]);
   IpcClient::sendTo(&noti_msg, sizeof(AaaStateReport_UsiOfm_Type), MwUtil::ip(SelfConf::shelf, SelfConf::slot, 0),OFM_RECV_IPC_MBOX) ; 
                }
 
                dusPrint("fm", PL_CMD, "ok/n");
        }
        catch (exception& ex)
        {
                dusPrint("fm", PL_CMD, "ex: %s/n", ex.what());
        }
        catch (...)
        {
                dusPrint("fm", PL_CMD, "ex: unknown/n");
        }
 
        return 0;
}
void* AaaStateManager::create()
{
 // Register alarm type.
 EnumUtil::alarm(OFM_ALM_AAA_DOWN,  "Aaadown");

 // Register alarm group.
 AlarmGroup::set(OFM_ALM_AAA_DOWN,  FM_ALG_COMM);
 switch (SelfConf::procType)
 {
  // MMP(24), RMP(24), MRMP(24)
  case MMP:
   return new AaaStateManager();

  default:
   return NULL;
 }
}

void AaaStateManager::notiCpsOfmInfo()
{
 MsgHeader_Type noti_msg;
 memset(&noti_msg, 0, sizeof(MsgHeader_Type));
 noti_msg.msg_id = Write16(_msg_OfmStateInd_OfmCps);
 IpcClient::sendTo(&noti_msg, sizeof(MsgHeader_Type), MwUtil::ip(SelfConf::shelf, SelfConf::slot, 0), ARC_INT_OAM_MBOX) ; 
}
///
// AaaStateManager::Provider class members

SnmpTable* AaaStateManager::Provider::table = NULL;

AaaStateManager::Provider::Provider()
{
 _rid = 0xFFFF;

 _stateCount = 0;
 _alarm = NULL;

 memset(&val, 0xFF, sizeof(AaaStateInfo));
}

AaaStateManager::Provider::~Provider()
{
 try
 {
  reset();
 }
 catch (...)
 {
 }
}

void AaaStateManager::Provider::set(word16 AaaId)
{
 if ((_rid == AaaId) && (_alarm != NULL))
 {
  Debug::print(cid, "nop[Aaa-%02d];AaaStateManager/n", _rid);

  return;
 }

 _rid = AaaId;

 if (!valid())
 {
  return;
 }
 val.AaaId = AaaId;
 val.AaaState = FM_OP_UNKNOWN;
 char sub[128];

 snprintf(sub, 128, "/Aaa_%d", _rid);
  
 _stateCount = 1;
 _alarmCount = 1;
 _alarm = new AlarmMapItem*[_alarmCount];

 _alarm[0] =
  &AlarmMap::item(SelfConf::shelf, SelfConf::slot, sub, OFM_ALM_AAA_DOWN, OFM_SEV_MAJOR);
 _alarm[0]->flag = FM_ADF_ACTIVE;
 _alarm[0]->filtered(false);
 

}
int AaaStateManager::Provider::sndStat()
{
 if(pre_state != val.AaaState)
        {
                SnmpAaaStateChange noti;
 
                memset(&noti, 0, sizeof(SnmpAaaStateChange));
 
                noti.msgHeader.msg_id = Write16(_msg_UsiAaaStateInd_OfmOagx);
 
                noti.body.AaaId    = Write16(val.AaaId);
  noti.body.AaaIpVer = Write32(val.AaaIpVer);
  if( val.AaaIpVer == IPV4)
         {
                 noti.body.AaaIpV4   =Write32(val.AaaIpV4);
         }
         else
         {
                 for(int n = 0 ; n < 16 ; n++)
                 {
                         noti.body.AaaIpV6[n] = val.AaaIpV6[n];
                 }
         }
                noti.body.AaaState  = Write8(val.AaaState);
                memcpy(&(noti.body.ReleaseReasonStr), &(val.ReleaseReasonStr),sizeof(val.ReleaseReasonStr));
                DateTime::fill(noti.body.AaacTimestamp, 11, DateTime::now());
   //TrapManager::onTrapSend(&noti, sizeof(SnmpAaaStateChange));

  //GmsClient::sendTo(&noti, sizeof(SnmpAaaStateChange), MwUtil::addr(MwUtil::localAddress(), OAGM_TRAP_MBOX_ID), WebEMT);
  TrapManager::send(&noti, sizeof(SnmpAaaStateChange), display, WebEMT);
  Debug::print(DateTime::now(), cid, "AaaStateManager::sendAaaStatus/n");
  
  timeval ts = DateTime::now().timeval();
  _alarm[0]->ts = ts;
  
  if(val.AaaState != FM_OP_ENABLED)
  {
   
   _alarm[0]->update(true);
  }
  else
  {

   if(pre_state != FM_OP_UNKNOWN)
    _alarm[0]->update(false);
         }
 }
 if ((table != NULL)&&(pre_state == FM_OP_UNKNOWN))
 {
  table->rows.add(this);
 }
  return 0;
}
void AaaStateManager::Provider::reset()
{
 if (table != NULL)
 {
  table->rows.remove(this);
 }

 _stateCount = 0;
 _alarm = NULL;

 _alarmCount = 0;

 _rid = 0xFFFF;

 memset(&val,0 , sizeof(AaaStateInfo));
 val.AaaId = 0xFFFF;
 val.AaaState = 0xFF;

}


bool AaaStateManager::Provider::valid()
{
 return (_rid < FM_MAX_AAA_COUNT);
}

void AaaStateManager::Provider::eval()
{
 if (!valid())
 {
  return;
 }
}

void* AaaStateManager::Provider::get()
{

 memcpy(&htonval,&val,sizeof(val));
 htonval.AaaId = Write16(val.AaaId);      
        htonval.AaaIpVer = Write32(val.AaaIpVer);     
        htonval.AaaIpV4 = Write32(val.AaaIpV4);          
 return &htonval;
}

void AaaStateManager::Provider::display(void* buffer, word32 len, bool enabled)
{
 if ((buffer == NULL) || (len != sizeof(SnmpAaaStateChange)))
 {
  return;
 }

 SnmpAaaStateChange& noti = *((SnmpAaaStateChange*)buffer);
 DateTime::fill(noti.body.AaacTimestamp, 11, DateTime::now());
 DateTime now = DateTime::now();
 string cur;

 char sid[32] = {0,};

 if (noti.body.AaaId != 0xFFFF)
 {
  snprintf(sid, 31, "Aaa-%02d", noti.body.AaaId);
 }
 else
 {
  snprintf(sid, 31, "Aaa-**-**");
 }
 if(noti.body.AaaState == 1)
  cur = "enable";
 else
  cur = "disable";
 Debug::print(now, cid, "Aaa_noti  %c%s-%02d%s/n",
   enabled ? ' ' : 'x',
   sid,
   noti.body.AaaId, cur.c_str());

 if (!enabled)
 {
  return;
 }

 // Append to state log.
 FILE* fp = TrapManager::statelog.fp();

 if (fp == NULL)
 {
  return;
 }

 const byte* ts = noti.body.AaacTimestamp;
 
 fprintf(fp, "[%s] %04d%02d%02d%02d%02d%02d %s-%02d -%2d%s/n",
   now.toString().substr(0, 19).c_str(),
   *(word16*)ts, ts[2], ts[3], ts[4], ts[5], ts[6],
   sid,
   noti.body.AaaId,
   noti.body.AaaState,cur.c_str());

 fflush(fp); 
}

}
#endif

VSCode 是一个非常流行的开发工具,它有许多功能和扩展插件,但是本身并没有直接的备份功能。然而,通过一些方法和技巧,我们可以实现对 VSCode 平台上的代码进行备份。 首先,我们可以使用版本控制系统(Version Control System,简称 VCS)来备份代码。VSCode 中集成了一些 VCS 工具,如 Git,可以轻松地进行代码版本管理。我们可以将代码存储在本地或远程 Git 仓库中,以便进行备份和恢复。只需在 VSCode 中初始化一个 Git 仓库,并将代码提交到仓库中,以获得代码的历史版本和备份。 其次,VSCode 还提供了一些扩展插件,可以帮助我们进行代码备份。有一些插件可以自动将代码备份到云存储服务(如 Dropbox、Google Drive 等)或本地指定目录中。这些插件可以根据我们的设置,定期将代码备份到指定的位置,并保留历史备份。通过安装并配置这些插件,我们可以轻松地自动化代码备份过程。 此外,我们还可以通过手动复制或导出项目文件来进行代码备份。在 VSCode 中,我们可以选择将项目文件复制到另一个目录或磁盘上的不同位置,以实现备份。此外,我们还可以导出整个项目为压缩文件(如 ZIP)进行备份。这种方法需要我们定期手动执行备份操作,但可以提供更灵活的备份方式。 总结起来,尽管 VSCode 平台本身没有直接的备份功能,但我们可以通过使用版本控制系统、安装扩展插件或手动复制/导出项目文件的方式进行代码备份。选择哪种方法主要取决于个人的需求和偏好。无论使用哪种方式,定期备份代码是保护我们工作成果的重要措施。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值