Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. /* header files are included here */
  2.  
  3. PCI_card card;
  4.  
  5. int main(void)
  6. {
  7. card.init_card(0);
  8.  
  9. return 0;
  10. }
  11.  
  12. #ifndef __PCI_CARD_H
  13. #define __PCI_CARD_H
  14.  
  15. /* header files are included here */
  16.  
  17. typedef struct {
  18. int32_t card_index;
  19. int32_t user_counter;
  20. } card_dev_t;
  21.  
  22. class PCI_card {
  23. public:
  24. PCI_card() : dev_descriptor(-1) { enlarge_vector(); }
  25.  
  26. int32_t init_card(int32_t card_num);
  27.  
  28. private:
  29. int32_t dev_descriptor;
  30.  
  31. public:
  32. static int32_t enlarge_vector();
  33.  
  34. private:
  35. static int32_t card_amount;
  36. static std::vector<card_dev_t> cards;
  37. };
  38.  
  39. #endif
  40.  
  41. /* header files are included here */
  42.  
  43. int32_t PCI_card::card_amount = -1;
  44. std::vector<card_dev_t> PCI_card::cards;
  45.  
  46. int32_t PCI_card::init_card(int32_t card_num)
  47. {
  48. if (card_num >= card_amount || card_num < 0)
  49. return -1;
  50.  
  51. card_dev_t new_card = {
  52. .card_index = card_num,
  53. .user_counter = 1
  54. };
  55.  
  56. cards[card_num] = new_card;
  57. dev_descriptor = card_num;
  58.  
  59. return 0;
  60. }
  61.  
  62. int32_t PCI_card::enlarge_vector()
  63. {
  64. card_amount = 10;
  65. card_dev_t null_card = {
  66. .card_index = -1,
  67. .user_counter = -1
  68. };
  69.  
  70. cards.resize(card_amount, null_card);
  71.  
  72. return card_amount;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement