Ejemplo n.º 1
0
//设置设备实现
func setDeviceImp(DevKind int, drv driverlayer.DriverBase, drvarg *driverlayer.DriverArg) error {
	if DevKind >= 0 && DevKind < MAX_DEVICE {
		if alldevice[DevKind].IsOccupy == false {
			alldevice[DevKind].IsOccupy = true
			alldevice[DevKind].drv = drv
			alldevice[DevKind].FactoryName = drv.GetFactoryName()
			alldevice[DevKind].drvarg = drvarg
			alldevice[DevKind].State = DEVICE_IDLE
			return nil
		} else {
			return DEV_ALREADY_IMPLEMENTED
		}
	}
	return DEV_NOT_FOUND
}
Ejemplo n.º 2
0
func StartDriverService(drivers []UseDriverCategory) error {
	var err error
	var v UseDriverCategory
	var k int
	var drvbase driverlayer.DriverBase
	var facname string

	Rollback := func(driver driverlayer.DriverBase, arg *driverlayer.DriverArg) {
		if err != nil {
			driver.Deinit(arg)
		}
	}

	for _, v = range drivers {
		drvbase = nil
		k, err = getDeviceIndex(v.Category)
		if err != nil {
			utils.Error("can't find Category impl:%s", v.Category)
			continue
		}
		facname = findFactoryParam(v.Kind)
		if facname == "" {
			utils.Error("can't find Category:%v's factory", v.Category)
			continue
		}

		switch k {
		case PIN:
			switch facname {
			case "南天":

				break

			case "通用类型":
				drvbase = &pin.PinGeneral{}
				break

			default:

			}

		case FP:
			switch facname {
			case "通用类型":
				drvbase = &finger.ZZFinger{}
				break

				//			case "天诚":
				//				drvbase = &finger.TCFinger{}
				//				break

			case "中正":
				drvbase = &finger.ZZFinger{}
				break

			default:

			}

		case PINGJIA:
			switch facname {
			case "南天":

				break

			case "升腾":
				drvbase = &pingjia.STPingjia{}
				break

			case "通用类型":
				drvbase = &pingjia.HTPingjia{}

			default:
			}

		case MSF:
			switch facname {
			case "实达":
				drvbase = &bankcard.SDMsf{}
				break

			default:

			}

		case IC:
			switch facname {
			case "通用类型":
				drvbase = &iccard.ICGeneral{}
				break
				//			case "升腾":
				//				drvbase = &iccard.STICCard{}
				//				break
			default:

			}

		case IDR:
			switch facname {
			case "通用类型":
				drvbase = &idccard.IDCGeneral{}
				break

				//			case "升腾":
				//				drvbase = &idccard.STIdr{}
				//				break
			default:

			}

		case PR2PRT:
			switch facname {
			case "PR2":
				drvbase = &pr2.OlevittePrinter{}
				break
			case "OKI":
				drvbase = &pr2.OkiPrinter{}
			default:

			}

		case KVM:
			switch facname {
			case "通用类型":
				drvbase = &kvm.KVMGeneral{}
				break
			}

		}
		//进行初始化
		if drvbase != nil {
			cat, _ := getDeviceCategory(k)
			utils.Info("%s  use %s driver", cat, drvbase.GetFactoryName())
			t := populateArg(v.Kind)
			setDeviceImp(k, drvbase, t)
			drvbase.Initdriver(t)
			defer Rollback(drvbase, t)
		} else {
			utils.Error(`Category %s could not find factory %s`, v.Category, facname)
		}
	}
	return err
}