| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- #pragma once
- #include "spHelper.h"
- #include "SimpleString.h"
- #include "Blob.h"
- //#define DeviceService_Method_GetDevInfo 65535
- //#define DeviceService_MethodSignature_GetDevInfo 296205965
- //
- //struct DeviceService_GetDevInfo_Req
- //{
- // void Serialize(SpBuffer &Buf)
- // {
- // }
- //};
- //
- //struct DeviceService_GetDevInfo_Ans
- //{
- // CSimpleStringA type;
- // CSimpleStringA model;
- // CSimpleStringA vendor;
- // int state;
- // WORD wMajor; //release major version
- // WORD wMinor; //release minor version
- // WORD wRevision; //bug repair version with the major and minor version remains the same
- // WORD wBuild; //compile version
- //
- // void Serialize(SpBuffer &Buf)
- // {
- // Buf & type & model & vendor & state & wMajor & wMinor & wRevision & wBuild;
- // }
- //};
- //
- //class DeviceService_ClientBase : public CClientSessionBase {
- //public:
- // DeviceService_ClientBase(CEntityBase *pEntity) : m_pEntityBase(pEntity), m_bSysManaged(false) {}
- //
- //protected:
- // virtual ~DeviceService_ClientBase() {}
- //
- //public:
- //
- // ErrorCodeEnum Connect(CSmartPointer<IAsynWaitSp> &spAsyncWait, const CSimpleStringA &strRemoteEntity)
- // {
- // CSmartPointer<IEntityFunction> pFunc = m_pEntityBase->GetFunction();
- //
- // CSimpleStringA strServiceName = strRemoteEntity + "Service";
- // ErrorCodeEnum Error = pFunc->ConnectRemoteEntity(this, (const char*)strRemoteEntity, (const char*)strServiceName, spAsyncWait);
- // if (Error == Error_Succeed) {
- // m_bSysManaged = true;
- // }
- // return Error;
- // }
- //
- // ErrorCodeEnum Connect(const CSimpleStringA &strRemoteEntity)
- // {
- // CSmartPointer<IAsynWaitSp> spAsyncWait;
- // ErrorCodeEnum Error = Connect(spAsyncWait, strRemoteEntity);
- // if (Error == Error_Succeed) {
- // Error = spAsyncWait->WaitAnswer();
- // }
- // return Error;
- // }
- //
- // ErrorCodeEnum GetDevInfo(DeviceService_GetDevInfo_Req &Req, CSmartPointer<IAsynWaitSp> &spAsyncWait, DWORD dwTimeout)
- // {
- // CSmartPointer<IClientSessionFunction> pFunc = GetFunction();
- // CAutoBuffer Buf = SpObject2Buffer(Req);
- // return pFunc->AsyncRequest(DeviceService_Method_GetDevInfo, DeviceService_MethodSignature_GetDevInfo, Buf, spAsyncWait, dwTimeout);
- // }
- //
- // ErrorCodeEnum GetDevInfo(DeviceService_GetDevInfo_Req &Req, DeviceService_GetDevInfo_Ans &Ans, DWORD dwTimeout)
- // {
- // CSmartPointer<IAsynWaitSp> spAsyncWait;
- // ErrorCodeEnum Error = GetDevInfo(Req, spAsyncWait, dwTimeout);
- // if (Error == Error_Succeed) {
- // bool bEnd = false;
- // Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd);
- // LOG_ASSERT(Error || bEnd);
- // }
- // return Error;
- // }
- //
- // bool SafeDelete()
- // {
- // if (!m_bSysManaged) {
- // delete this;
- // }
- // return m_bSysManaged;
- // }
- //
- //protected:
- // bool m_bSysManaged;
- // CEntityBase *m_pEntityBase;
- //};
- //
- //ErrorCodeEnum SpGetDeviceInfo(CEntityBase *pEntity, const CSimpleStringA &devDevEntityName,
- // CSimpleStringA &strType, CSimpleStringA &strModel, CSimpleStringA &strVendor, int &nState, CBlob &blobVersion)
- //{
- // DeviceService_ClientBase *pClient = new DeviceService_ClientBase(pEntity);
- // ErrorCodeEnum rc = pClient->Connect(devDevEntityName);
- // if (rc == Error_Succeed)
- // {
- // DeviceService_GetDevInfo_Req req;
- // DeviceService_GetDevInfo_Ans ans;
- // rc = pClient->GetDevInfo(req, ans, 5000);
- // if (rc == Error_Succeed)
- // {
- // strType = ans.type;
- // strModel = ans.model;
- // strVendor = ans.vendor;
- // nState = ans.state;
- // blobVersion.Alloc(8);
- // ((BYTE*)blobVersion.m_pData)[0] = (ans.wMajor >> 8) & 0xFF;
- // ((BYTE*)blobVersion.m_pData)[1] = ans.wMajor & 0xFF;
- // ((BYTE*)blobVersion.m_pData)[2] = (ans.wMinor >> 8) & 0xFF;
- // ((BYTE*)blobVersion.m_pData)[3] = ans.wMinor & 0xFF;
- // ((BYTE*)blobVersion.m_pData)[4] = (ans.wRevision >> 8) & 0xFF;
- // ((BYTE*)blobVersion.m_pData)[5] = ans.wRevision & 0xFF;
- // ((BYTE*)blobVersion.m_pData)[6] = (ans.wBuild >> 8) & 0xFF;
- // ((BYTE*)blobVersion.m_pData)[7] = ans.wBuild & 0xFF;
- // }
- // pClient->GetFunction()->CloseSession();
- // }
- // pClient->SafeDelete();
- // return rc;
- //}
- ErrorCodeEnum SpGetAllDevices(CEntityBase *pEntity, CAutoArray<CSimpleStringA> &devs)
- {
- CSmartPointer<IConfigInfo> pConfig;
- ErrorCodeEnum rc = pEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
- if (rc == Error_Succeed)
- {
- int nCount(0);
- rc = pConfig->ReadConfigValueInt("Device", "Number", nCount);
- if (rc == Error_Succeed && nCount>0)
- {
- devs.Init(nCount);
- for(int i=0; i<nCount; i++)
- {
- CSimpleStringA str = CSimpleStringA::Format("%d", i+1);
- rc = pConfig->ReadConfigValue("Device", (const char*)str, devs[i]);
- }
- }
- }
- return rc;
- }
- ErrorCodeEnum SpGetDeviceInfo(CEntityBase *pCallerEntity, const CSimpleStringA &devDeviceName,
- CSimpleStringA &strModel, CSimpleStringA &strVendor, CSimpleStringA &strVersion)
- {
- CSmartPointer<IConfigInfo> pConfig;
- ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
- if (rc == Error_Succeed)
- {
- CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName;
- pConfig->ReadConfigValue(strSection, "Vendor", strVendor);
- pConfig->ReadConfigValue(strSection, "Version", strVersion);
-
- strModel = devDeviceName;
- if (!strVendor.IsNullOrEmpty())
- {
- strModel += ".";
- strModel += strVendor;
- }
- if (!strVersion.IsNullOrEmpty())
- {
- strModel += ".";
- strModel += strVersion;
- }
- }
- return rc;
- }
- ErrorCodeEnum SpGetDevAdaptorPath(CEntityBase *pCallerEntity,
- const CSimpleStringA &devDeviceName,
- CSimpleStringA &strDevAdaptorPath)
- {
- CSmartPointer<IConfigInfo> pConfig;
- ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
- if (rc == Error_Succeed)
- {
- CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName;
-
- strDevAdaptorPath = devDeviceName;
- CSimpleStringA str;
- pConfig->ReadConfigValue(strSection, "Vendor", str);
- if (!str.IsNullOrEmpty())
- {
- strDevAdaptorPath += ".";
- strDevAdaptorPath += str;
- }
- str.Clear();
- pConfig->ReadConfigValue(strSection, "Version", str);
- if (!str.IsNullOrEmpty())
- {
- strDevAdaptorPath += ".";
- strDevAdaptorPath += str;
- }
- str.Clear();
- pConfig->ReadConfigValue(strSection, "Batch", str);
- if (!str.IsNullOrEmpty())
- {
- strDevAdaptorPath += ".";
- strDevAdaptorPath += str;
- }
- CSimpleStringA strDepPath;
- pCallerEntity->GetFunction()->GetPath("Dep", strDepPath);
- strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll",
- (const char*)strDepPath,
- (const char*)strDevAdaptorPath);
- }
- return rc;
- }
- // add by ly
- ErrorCodeEnum SpGetDevAdaptorPathByIndex(int nIndex,
- CEntityBase *pCallerEntity,
- const CSimpleStringA &devDeviceName,
- CSimpleStringA &strDevAdaptorPath)
- {
- CSmartPointer<IConfigInfo> pConfig;
- ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
- if (rc == Error_Succeed)
- {
- char tmp[64] = {0};
- CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName;
- strDevAdaptorPath = devDeviceName;
- CSimpleStringA str;
- sprintf(tmp, "Vendor_%d", nIndex);
- pConfig->ReadConfigValue(strSection, tmp, str);
- if (!str.IsNullOrEmpty())
- {
- strDevAdaptorPath += ".";
- strDevAdaptorPath += str;
- }
- str.Clear();
- sprintf(tmp, "Version_%d", nIndex);
- pConfig->ReadConfigValue(strSection, tmp, str);
- if (!str.IsNullOrEmpty())
- {
- strDevAdaptorPath += ".";
- strDevAdaptorPath += str;
- }
- str.Clear();
- sprintf(tmp, "Batch_%d", nIndex);
- pConfig->ReadConfigValue(strSection, tmp, str);
- if (!str.IsNullOrEmpty())
- {
- strDevAdaptorPath += ".";
- strDevAdaptorPath += str;
- }
- CSimpleStringA strDepPath;
- pCallerEntity->GetFunction()->GetPath("Dep", strDepPath);
- strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll",
- (const char*)strDepPath,
- (const char*)strDevAdaptorPath);
- }
- return rc;
- }
|